Bin to hex converter in 16-bit DOS assembly
Just a quick code like putting your keyboard where your brain is. There should be another way of doing this. I hate this code.
start:
xor al, al
xor bl, bl
xor cl, cl
mov dl, 4 ; use dl as counter
input:
mov ah, 00
int 16h
cmp ah, 1ch
je exit
cmp al, '0'
jb input
cmp al, '1'
ja input
convert:
mov cl, dl
dec cl ; dl - 1
sub al, 30h ; get original value
shl al, cl ; place in the appropriate bit position
or bl, al ; save in bl
dec dl ; prepare for the next bit
jnz input ; must be 4 bits
cmp bl, 9
ja letter
jbe number
letter:
add bl, 37h ; because 'A' - 37h is 0Ah
jmp here
number:
add bl, 30h ; because '0' - 30h is 00h
here:
call display
jmp start
display:
mov ah, 02h
mov dl, bl
int 21h
ret
exit:
int 20h
Try this out, get the assembler here.

;here is my nooob code for binhex
i think i had a lot of worthless lines
;converstion
;anyway have fun! jejejeje
lea si,save
xor bx,bx
xor cx,cx
input_:
mov ah,0
int 16h
cmp ah,1ch
je process_p
cmp cl,4
jne clnz_
xor cl,cl
clnz_:
cmp al,’0′
jb input_
cmp al,’1′
ja input_
call echo_
jmp input_
process_p:
cmp cl,4
jne input_
process_:
lea di,save2
mov cx,bx
dec bx
xxx:
mov dh,4
mov dl,0
dh4lop: ;for(int i=4;i!=0;–i)
shr dl,1
mov al,[si+bx]
cmp al,’0′
je done_
cmp al,’1′
je one_
jmp done_
one_:
mov al,1
shl al,3
add dl,al
jmp done_
done_:
dec bx
dec cx
;jz save_
dec dh
jnz dh4lop
save_:
cmp dl,9
ja char_
add dl,30h
jmp write_
char_:
add dl,37h
write_:
mov [di],dl
inc di
cmp cx,0
ja xxx
gogogo:
mov ah,02
mov dl,10
int 21h
mov dl,13
int 21h
lea si,save2
xor bx,bx
xx:
mov al,[si+bx]
cmp al,’$’
je xit_
inc bx
jmp xx
xit_:
dec bx
mov ah,02
mov dl,[si+bx]
int 21h
cmp bx,0
jne xit_
int 20h
save db 255 dup(’$')
save2 db 255 dup(’$')
echo_:
inc cl
mov ah,02
mov dl,al
int 21h
mov [si+bx],dl
inc bx
ret
Comment by sykes — August 25, 2006 @ 9:01 pm
cool!
that is more friendly than my code at run time.
Comment by eradicus — August 25, 2006 @ 9:30 pm
bowling for talibans. :p
Comment by south coast marine — August 25, 2006 @ 9:42 pm
need help any one , need write a programma DEC –>HEX 8086 , fast can any one help me ?
Comment by drejan — May 21, 2007 @ 12:11 am
mm
Comment by shabgardehasheg_m — July 14, 2008 @ 6:25 pm