This is a shorter and lazier version of hex to binary conversion. It displays right away the binary equivalent of a valid hexadecimal and waits user to press enter key to end. Thanks to sir for the convert algo…hehe:)
check:
mov ah, 00
int 16h
cmp ah, 1ch ; scan key for enter key
je exit
cmp al, ‘0′
jb check
cmp al, ‘9′
ja ucase
sub al, 30h
call convert
jmp check
ucase:
cmp al, ‘A’
jb check
cmp al, ‘F’
ja lcase
sub al, 37h
call convert
jmp check
lcase:
cmp al, ‘a’
jb check
cmp al, ‘f’
ja check
sub al, 57h
call convert
jmp check
exit:
int 20h
loop check
;———————–convert——————————
convert:
mov ch, 4 ; 4 bits
mov cl, 3
mov bl, al
xxx:
mov al, bl
shr al, cl
and al, 01 ; bit masking- isolate least bit 0
add al, 30h
mov ah, 02 ; display binary equivalent
mov dl, al
int 21h
dec cl
dec ch
jnz xxx
mov dl, ‘ ‘
int 21h
ret
All comments are moderated. Your comments will not appear here unless approved by the blog owner. Thank you.