aboutsummaryrefslogtreecommitdiff
path: root/amforth-6.5/avr8/words/popcnt.asm
diff options
context:
space:
mode:
Diffstat (limited to 'amforth-6.5/avr8/words/popcnt.asm')
-rw-r--r--amforth-6.5/avr8/words/popcnt.asm29
1 files changed, 29 insertions, 0 deletions
diff --git a/amforth-6.5/avr8/words/popcnt.asm b/amforth-6.5/avr8/words/popcnt.asm
new file mode 100644
index 0000000..66f8f47
--- /dev/null
+++ b/amforth-6.5/avr8/words/popcnt.asm
@@ -0,0 +1,29 @@
+; ( n1 -- n2 )
+; Arithmetics
+; count the Number of 1 bits (population count)
+VE_POPCNT:
+ .dw $ff06
+ .db "popcnt"
+ .dw VE_HEAD
+ .set VE_HEAD = VE_POPCNT
+XT_POPCNT:
+ .dw PFA_POPCNT
+PFA_POPCNT:
+ movw zl, tosl
+ clr tosl
+ rcall PFA_POPCNT1
+ mov zl, zh
+ rcall PFA_POPCNT1
+ clr tosh
+ jmp_ DO_NEXT
+
+PFA_POPCNT1:
+ ldi tosh, 8
+PFA_POPCNT2:
+ ror zl
+ ;breq PFA_POPCNT3
+ adc tosl, zeroh
+ dec tosh
+ brne PFA_POPCNT2
+POPCNT3:
+ ret \ No newline at end of file