I'm trying to return the count of bits in a number using a lookup. While this is working for my commented "bitchecks" block it's not lookup for my actual lookups. I always get "0" as my return. My end result is to compare the performance between my "bit checks" routine and using a lookup.
global _start
section .data
bitcount db 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1
db 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 1, 2
db 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3
db 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3
db 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3
db 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4
db 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5
db 6, 4, 5, 5, 6, 5, 6, 6, 7, 1, 2, 2, 3, 2, 3, 3, 4
db 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3
db 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4
db 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5
db 6, 5, 6, 6, 7, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5
db 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5
db 6, 6, 7, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6
db 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8
section .text
_start:
mov ecx, 100000000 ;test loop count
mov edi, 00000000111111111111111111111111b ;number to get the bit count for
;mov edi, 10000000000000000000000000000000b
.testing:
xor ebx, ebx ;clear out the return
xor eax, edi ;keep a detroyable version of the number
;.bitchecks:
; bsf esi, eax
; jz .done
; inc ebx
; btr eax, esi
; jmp .bitchecks
xor edx, edx ;clear the register
mov dl, al ;set the edx to just the lowest part of the number
movzx ebx, byte [bitcount + edx] ;return the byte count via lookup
mov dl, ah ;set the edx to the next part of the number
movzx esi, byte [bitcount + edx] ;return the byte count via lookup
add ebx, esi ;add the lookup value to the total count
bswap eax ;swap the low and high parts of the target number
mov dl, al ;set the edx to just the lowest part, next lookup
movzx esi, byte [bitcount + edx] ;return the byte count via lookup
add ebx, esi ;add the lookup value to the total count
mov dl, ah ;set the edx to the next part of the number
movzx esi, byte [bitcount + edx] ;return the bute count via lookup
add ebx, esi ;add the final count to the return
.done:
dec ecx
jnz .testing
.exit:
;the return should be in ebx as the return code
mov eax, 1
int 0x80