2019-08-31 00:18:05 +02:00
|
|
|
popcnt:
|
|
|
|
push bx
|
|
|
|
push cx
|
|
|
|
|
|
|
|
mov bx, ax
|
|
|
|
and ax, 0x5555 ; 8x 01
|
|
|
|
and bx, 0xaaaa ; 8x 10
|
2019-09-10 15:44:44 +02:00
|
|
|
shr bx, 1
|
2019-08-31 00:18:05 +02:00
|
|
|
add ax, bx
|
|
|
|
|
|
|
|
mov bx, ax
|
|
|
|
and ax, 0x3333 ; 4x 0011
|
|
|
|
and bx, 0xcccc ; 4x 1100
|
|
|
|
mov cl, 2
|
2019-09-10 15:44:44 +02:00
|
|
|
shr bx, cl
|
2019-08-31 00:18:05 +02:00
|
|
|
add ax, bx
|
|
|
|
|
|
|
|
mov bx, ax
|
|
|
|
and ax, 0x0f0f ; 2x 00001111
|
|
|
|
and bx, 0xf0f0 ; 2x 11110000
|
|
|
|
mov cl, 4
|
2019-09-10 15:44:44 +02:00
|
|
|
shr bx, cl
|
2019-08-31 00:18:05 +02:00
|
|
|
add ax, bx
|
|
|
|
|
|
|
|
add al, ah
|
|
|
|
xor ah, ah
|
|
|
|
|
|
|
|
pop cx
|
|
|
|
pop bx
|
|
|
|
ret
|