-
-
Save ehzawad/f444acbaa685887a79f23c4646d2651c to your computer and use it in GitHub Desktop.
binary tricks on numbers
This file contains 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
.model small | |
.stack 100h | |
.data | |
str1 db 'Ones :$' | |
str2 db ' zero :$' | |
ones db '0' | |
zeros db '0' | |
.code | |
main proc | |
mov ax,@data | |
mov ds,ax | |
mov bl,00001000b | |
mov dl,00000100b | |
mov cx,8 | |
reversetodh1: | |
rol bl,1 | |
rcr dh,1 | |
loop reversetodh1 | |
mov bl,dh | |
mov dh,0 ;set zero to be safe | |
mov cx,8 | |
reversetodh2: | |
rol dl,1 | |
rcr dh,1 | |
loop reversetodh2 | |
mov dl,dh | |
;now move to desired registers | |
mov ch,bl | |
mov bh,dl | |
add bh,ch | |
mov cx,8 | |
countstuff: | |
rol bh,1 | |
jc one | |
jnc zero | |
one: | |
inc ones | |
jmp ex | |
Zero: | |
inc zeros | |
ex: | |
loop countstuff | |
mov ah,9 | |
lea dx,str1 | |
int 21h | |
mov ah,2 | |
mov dl,ones | |
int 21h | |
mov ah,9 | |
lea dx,str2 | |
int 21h | |
mov ah,2 | |
mov dl,zeros | |
int 21h | |
main endp | |
end main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment