I'm not sure this is the correct forum for this, but since I'm not a member of any other technical forums I thought I'd give it a shot anyway.
I'm writing a program to convert 2-digit BCD number to HEX number is assembly (using Turbo Assembler/TASM). So far this is the code I've written, but it's giving wrong outputs. Can anyone find what is wrong with it?
I'm writing a program to convert 2-digit BCD number to HEX number is assembly (using Turbo Assembler/TASM). So far this is the code I've written, but it's giving wrong outputs. Can anyone find what is wrong with it?
Rich (BB code):
.model small
.stack 100
.data
msg1 db 10,13,"Enter the 2 digit BCD number: $"
msg2 db 10,13,"The equivalent HEX number is: $"
no db ?
.code
main proc
mov ax,@data
mov ds,ax
lea dx,msg1
mov ah,9
int 21h
mov ah,1
int 21h
sub al,30h
sub dl,10
mul dl
mov no,al
mov ah,1
int 21h
cmp al,0dh
je exit
sub al,30h
add no,al
lea dx,msg2
mov al,9
int 21h
mov al,no
and al,0f0h
mov cl,4
shr al,cl
mov dl,al
cmp dl,9
jg alpha1
add dl,30h
jmp next
alpha1: add dl,37h
next: mov ah,2
int 21h
mov al,no
and al,0fh
mov dl,al
cmp dl,9
jg alpha2
add dl,30h
jmp next2
alpha2: add dl,37h
next2: mov ah,2
int 21h
jmp exit1
exit: lea dx,msg2
mov ah,9
int 21h
mov al,no
mov cl,10
mov ah,0
div cl
mov dl,al
add dl,30h
mov ah,2
int 21h
exit1: mov ah,4ch
int 21h
main endp
end main