int 21h
endm
inputbcd macro num
mov cx,05h
mov bx,10000
b1: mov ah,01h
int 21h
sub al,30h
mov ah,00h
mul bx
add num,ax
push cx
mov dx,0000h
mov ax,bx
mov cx,10
div cx
mov bx,ax
pop cx
loop b1
endm
inputhex macro num
mov cx,04h
mov bx,1000h
a1: mov ah,01h
int 21h
cmp al,39h
jle a2
cmp al,59h
jle a2a
sub al,20h
a2a: sub al,07h
a2: sub al,30h
mov ah,00h
mul bx
add num,ax
ror bx,04h
loop a1
endm
.model small
.stack
.data
num dw 0000h
msg0 db 10,13,'------MENU-----$'
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 HEX NUMBER: $'
msg5 db 10,13,'ENTER BCD NUMBER: $'
msg6 db 10,13,'BCD EQUI OF HEX: $'
msg7 db 10,13,'HEX EQUI OF BCD: $'
msgn db 10,13,'$'
.code
main proc
mov ax,@data
mov ds,ax
m: disp msg0
disp msg1
disp msg2
disp msg3
disp msgn
mov ah,01h
int 21h
cmp al,'1'
je inp1
cmp al,'2'
je inp2
cmp al,'3'
je ex
ex: mov ax,4c00h
int 21h
inp2: disp msg5
inputbcd num
disp msg7
mov ax,num
call showhex
jmp m
inp1: disp msg4
inputhex num
disp msg6
mov ax,num
call showbcd
jmp m
endp main
;hex to bcd
showbcd proc near
push bx
push cx
push dx
mov cx,0000h
mov bx,000Ah
d1:
mov dx,0000h
div bx
push dx
inc cx
cmp al,00h
jne d1
d2:
pop dx
add dl,30h
mov ah,02h
int 21h
dec cx
jnz d2
pop dx
pop cx
pop bx
ret
endp
;showhex of bcd
showhex proc near
mov cx,0000h
mov bx,10h
d5:
mov dx,0000h
div bx
push dx
inc cx
cmp ax,0000h
jne d5
d6:
pop dx
cmp dx,0009h
jle d7
add dx,07h
d7:
add dx,30h
mov ah,02h
int 21h
loop d6
ret
endp
end
No comments:
Post a Comment