ALP for HEX to BCD BCD to HEX
3. Write 8086 ALP to convert 4-digit Hex number into its equivalent BCD number and 5-digit BCD number into its equivalent HEX number. Make your program user friendly to accept the choice from user for: (a) HEX to BCD b) BCD to HEX (c) EXIT. Display proper strings to prompt the user while accepting the input and displaying the result.
; HEX to BCD no
.model small
disp macro msg
lea dx,msg
mov ah,09h
int 21h
endm
.data
msg1 db 10,13,"enter the hex no: $"
msg2 db 10,13,"bcd no is: $"
arr dw 10 dup(0)
.code
mov ax,@data
mov ds,ax
disp msg1
mov ah,01h
int 21h
sub al,30h
cmp al,09h
jbe next1
sub al,07h
next1: mov bh,00h
mov bl,al
mov cl,0Ch
rol bl,cl
mov ah,01h
int 21h
sub al,30h
cmp al,09h
jbe next2
sub al,07h
next2: mov bh,00h
mov bl,al
mov cl,08h
rol bl,cl
mov ah,01h
int 21h
sub al,30h
cmp al,09h
jbe next3
sub al,07h
next3: mov bh,00h
mov bl,al
mov cl,04h
rol bl,cl
mov ah,01h
int 21h
sub al,30h
cmp al,09h
jbe next4
sub al,07h
next4: mov bh,00h
mov bl,al
lea si,arr
mov ax,bx
mov dx,0000h
mov bx,03E8h
div bx
mov [si],ax
inc si
inc si
mov ax,dx
mov dx,0000h
mov bx,064h
div bx
mov [si],ax
inc si
inc si
mov ax,dx
mov dx,0000h
mov bx,0Ah
div bx
mov [si],ax
inc si
inc si
mov ax,dx
mov dx,0000h
mov bx,01h
div bx
mov [si],ax
lea si,arr
mov ax,[si]
mov cl,0Ch
rol ax,cl
mov bx,ax
inc si
inc si
mov ax,[si]
mov cl,08h
rol ax,cl
add bx,ax
inc si
inc si
mov ax,[si]
mov cl,04h
rol ax,cl
add bx,ax
inc si
inc si
mov ax,[si]
add bx,ax
disp msg2
mov cx,0204h
mov dh,bh
up1: rol dh,cl
mov dl,dh
and dl,0fh
cmp dl,09h
jbe next5
add dl,07h
next5: add dl,30h
mov ah,02h
int 21h
dec ch
jnz up1
mov cx,0204h
mov dh,bl
up2: rol dh,cl
mov dl,dh
and dl,0fh
cmp dl,09h
jbe next6
add dl,07h
next6: add dl,30h
mov ah,02h
int 21h
dec ch
jnz up2
mov ah,04ch
int 21h
end
;BCD to HEX
.model small
.data
msg1 db 10,13,"Enter 5 digit BCD No: $"
msg2 db 10,13,"The equivalent hex No. is: $"
arr dw 5 dup(0)
.code
mov ax,@data
mov ds,ax
lea dx,msg1
mov ah,09h
int 21h
lea si,arr
mov ah,01h
int 21h
sub al,30h
mov ah,00h
mov bx,2710h
mul bx
mov [si],ax
inc si
inc si
mov ah,01h
int 21h
sub al,30h
mov ah,00h
mov bx,03E8h
mul bx
mov [si],ax
inc si
inc si
mov ah,01h
int 21h
sub al,30h
mov ah,00h
mov bx,0064h
mul bx
mov [si],ax
inc si
inc si
mov ah,01h
int 21h
sub al,30h
mov ah,00h
mov bx,000Ah
mul bx
mov [si],ax
inc si
inc si
mov ah,01h
int 21h
sub al,30h
mov ah,00h
mov bx,01h
mul bx
mov [si],ax
inc si
inc si
lea si,arr
mov bx,[si]
inc si
inc si
mov ch,04h
up: add bx,[si]
inc si
inc si
dec ch
jnz up
lea dx,msg2
mov ah,09h
int 21h
mov cx,0204h
mov dh,bh
up1: rol dh,cl
mov dl,dh
and dl,0fh
cmp dl,09h
jbe next1
add dl,07h
next1: add dl,30h
mov ah,02h
int 21h
dec ch
jnz up1
mov cx,0204h
mov dh,bl
up2: rol dh,cl
mov dl,dh
and dl,0fh
cmp dl,09h
jbe next2
add dl,07h
next2: add dl,30h
mov ah,02h
int 21h
dec ch
jnz up2
mov ah,04ch
int 21h
end
0 comments:
Post a Comment