aboutsummaryrefslogtreecommitdiff
path: root/amforth-6.5/avr8/words/popcnt.asm
blob: 66f8f471006398f3cc83d589d69f78a8bc271788 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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