.model small
disp macro a
mov ah,09h
lea dx,a
int 21h
endm
.data
msg1 db 10,13,"1.Hex to BCD.$"
msg2 db 10,13,"2.BCD to Hex.$"
msg3 db 10,13,"3.Exit.$"
msg4 db 10,13,"Enter your choice:$"
msg5 db 10,13,"Invalid choice.Re-enter choice.$"
msg6 db 10,13,"$"
msg7 db 10,13,"Enter the HEX no:$"
msg8 db 10,13,"The corresponding BCD no is:$"
msg9 db 10,13,"Enter the BCD no:$"
msg10 db 10,13,"The corresponding HEX no is:$"
result dw 0000h
temp dw 000Ah
cnt db 00h
.code
main:
mov ax,@data
mov ds,ax
menu:
disp msg6
disp msg1
disp msg2
disp msg3
disp msg4
mov ah,01h
int 21h
mov bl,al
sub bl,30h
cmp bl,01
je h2b
cmp bl,02
je b2h
cmp bl,03
je exit
disp msg5
jmp menu
exit:
mov ah,4ch
int 21h
h2b:
disp msg7
mov ax,0000h
call accept
disp msg8
mov ax,bx
up1:
mov dx,0000
div temp
push dx
inc cnt
cmp ax,0000h
jnz up1
up2:
pop dx
add dl,30h
mov ah,02h
int 21h
dec cnt
jnz up2
jmp menu
b2h:
disp msg9
mov bx,0000h
mov cl,05h
up3:
mov ax,000Ah
mul bx
mov bx,ax
mov ah,01h
int 21h
sub al,30h
mov ah,00h
add bx,ax
dec cl
jnz up3
mov result,bx
disp msg10
call print
jmp menu
accept proc near
mov ah,01h
int 21h
sub al,30h
cmp al,09h
jle l1
sub al,07h
l1:
mov ah,00
shl ax,12
mov bx,ax
mov ah,01h
int 21h
sub al,30h
cmp al,09h
jle l2
sub al,07h
l2:
mov ah,00
shl ax,08
add bx,ax
mov ah,01h
int 21h
sub al,30h
cmp al,09h
jle l3
sub al,07h
l3:
mov ah,00
shl ax,04
add bx,ax
mov ah,01h
int 21h
sub al,30h
cmp al,09h
jle l4
sub al,07h
l4:
mov ah,00
add bx,ax
ret
accept endp
print proc near
mov bx,result
shr bx,0Ch
cmp bl,09h
jle l5
add bl,07h
l5:
add bl,30h
mov dl,bl
mov ah,02h
int 21h
mov bx,result
shr bx,08h
and bl,0Fh
cmp bl,09h
jle l6
add bl,07h
l6:
add bl,30h
mov dl,bl
mov ah,02h
int 21h
mov bx,result
shr bx,04h
and bl,0Fh
cmp bl,09h
jle l7
add bl,07h
l7:
add bl,30h
mov dl,bl
mov ah,02h
int 21h
mov bx,result
and bl,0Fh
cmp bl,09h
jle l8
add bl,07h
l8:
add bl,30h
mov dl,bl
mov ah,02h
int 21h
ret
print endp
end main
end
--------------------------------------------------OUTPUT---------------------------------------------
D:\TASM\BIN>edit hbc.asm
D:\TASM\BIN>tasm hbc.asm
Turbo Assembler Version 4.1 Copyright (c) 1988, 1996 Borland International
Assembling file: hbc.asm
Error messages: None
Warning messages: None
Passes: 1
Remaining memory: 415k
D:\TASM\BIN>tlink hbc.obj
Turbo Link Version 7.1.30.1. Copyright (c) 1987, 1996 Borland International
Warning: No stack
D:\TASM\BIN>hbc
1.Hex to BCD.
2.BCD to Hex.
3.Exit.
Enter your choice:1
Enter the HEX no:FFFF
The corresponding BCD no is:65535
1.Hex to BCD.
2.BCD to Hex.
3.Exit.
Enter your choice:2
Enter the BCD no:65535
The corresponding HEX no is:FFFF
1.Hex to BCD.
2.BCD to Hex.
3.Exit.
Enter your choice:3
D:\TASM\BIN>
disp macro a
mov ah,09h
lea dx,a
int 21h
endm
.data
msg1 db 10,13,"1.Hex to BCD.$"
msg2 db 10,13,"2.BCD to Hex.$"
msg3 db 10,13,"3.Exit.$"
msg4 db 10,13,"Enter your choice:$"
msg5 db 10,13,"Invalid choice.Re-enter choice.$"
msg6 db 10,13,"$"
msg7 db 10,13,"Enter the HEX no:$"
msg8 db 10,13,"The corresponding BCD no is:$"
msg9 db 10,13,"Enter the BCD no:$"
msg10 db 10,13,"The corresponding HEX no is:$"
result dw 0000h
temp dw 000Ah
cnt db 00h
.code
main:
mov ax,@data
mov ds,ax
menu:
disp msg6
disp msg1
disp msg2
disp msg3
disp msg4
mov ah,01h
int 21h
mov bl,al
sub bl,30h
cmp bl,01
je h2b
cmp bl,02
je b2h
cmp bl,03
je exit
disp msg5
jmp menu
exit:
mov ah,4ch
int 21h
h2b:
disp msg7
mov ax,0000h
call accept
disp msg8
mov ax,bx
up1:
mov dx,0000
div temp
push dx
inc cnt
cmp ax,0000h
jnz up1
up2:
pop dx
add dl,30h
mov ah,02h
int 21h
dec cnt
jnz up2
jmp menu
b2h:
disp msg9
mov bx,0000h
mov cl,05h
up3:
mov ax,000Ah
mul bx
mov bx,ax
mov ah,01h
int 21h
sub al,30h
mov ah,00h
add bx,ax
dec cl
jnz up3
mov result,bx
disp msg10
call print
jmp menu
accept proc near
mov ah,01h
int 21h
sub al,30h
cmp al,09h
jle l1
sub al,07h
l1:
mov ah,00
shl ax,12
mov bx,ax
mov ah,01h
int 21h
sub al,30h
cmp al,09h
jle l2
sub al,07h
l2:
mov ah,00
shl ax,08
add bx,ax
mov ah,01h
int 21h
sub al,30h
cmp al,09h
jle l3
sub al,07h
l3:
mov ah,00
shl ax,04
add bx,ax
mov ah,01h
int 21h
sub al,30h
cmp al,09h
jle l4
sub al,07h
l4:
mov ah,00
add bx,ax
ret
accept endp
print proc near
mov bx,result
shr bx,0Ch
cmp bl,09h
jle l5
add bl,07h
l5:
add bl,30h
mov dl,bl
mov ah,02h
int 21h
mov bx,result
shr bx,08h
and bl,0Fh
cmp bl,09h
jle l6
add bl,07h
l6:
add bl,30h
mov dl,bl
mov ah,02h
int 21h
mov bx,result
shr bx,04h
and bl,0Fh
cmp bl,09h
jle l7
add bl,07h
l7:
add bl,30h
mov dl,bl
mov ah,02h
int 21h
mov bx,result
and bl,0Fh
cmp bl,09h
jle l8
add bl,07h
l8:
add bl,30h
mov dl,bl
mov ah,02h
int 21h
ret
print endp
end main
end
--------------------------------------------------OUTPUT---------------------------------------------
D:\TASM\BIN>edit hbc.asm
D:\TASM\BIN>tasm hbc.asm
Turbo Assembler Version 4.1 Copyright (c) 1988, 1996 Borland International
Assembling file: hbc.asm
Error messages: None
Warning messages: None
Passes: 1
Remaining memory: 415k
D:\TASM\BIN>tlink hbc.obj
Turbo Link Version 7.1.30.1. Copyright (c) 1987, 1996 Borland International
Warning: No stack
D:\TASM\BIN>hbc
1.Hex to BCD.
2.BCD to Hex.
3.Exit.
Enter your choice:1
Enter the HEX no:FFFF
The corresponding BCD no is:65535
1.Hex to BCD.
2.BCD to Hex.
3.Exit.
Enter your choice:2
Enter the BCD no:65535
The corresponding HEX no is:FFFF
1.Hex to BCD.
2.BCD to Hex.
3.Exit.
Enter your choice:3
D:\TASM\BIN>