Created
April 14, 2014 16:20
-
-
Save warabanshi/10662517 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
segment .data | |
data dq 0xfedcba9876543210 | |
sum dq 0 | |
segment .text | |
global main | |
main: | |
push rbp | |
mov rbp, rsp | |
sub rsp, 16 | |
; Register usage | |
; | |
; rax : bits being examined | |
; rbx : carry bit after bt, setc | |
; rcx : loop counter, 0-63 | |
; rdx : sum of 1 bits | |
; | |
mov rax, [data] | |
xor ebx, ebx | |
xor ecx, ecx | |
xor edx, edx | |
while: | |
cmp rcx, 64 | |
jnl end_while | |
bt rax, 0 | |
setc bl | |
add edx, ebx | |
shr rax, 1 | |
inc rcx | |
jmp while | |
end_while: | |
mov [sum], rdx | |
xor eax, eax | |
leave | |
ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment