Pages

Search in This Blog

Thursday 16 February 2012

Addition of two packed BCD numbers entered through keyboard


  • Write an 8086 program that adds two packed BCD numbers input from the keyboard and computes and displays the result on the system video monitor
  • Data should be in the form 64+89= The answer 153 should appear in the next line.
Program: 
Mov dx, buffer address
Mov ah,0a
Mov si,dx
Mov byte ptr [si], 8
Int 21
Mov ah,0eh
Mov al,0ah
Int 10 ;                               BIOS service 0e line feed position cursor
sub byte ptr[si+2], 30h
sub byte ptr[si+3], 30h
sub byte ptr[si+5], 30h
sub byte ptr[si+6], 30h
Mov cl,4
Rol byte ptr [si+3],cl
Rol byte ptr [si+6],cl
Ror word ptr [si+2], cl
Ror word ptr [si+2], cl
Mov al, [si+3]
Add al, [si+6]
Daa
Mov bh,al
Jnc display
Mov al,1
Call display
Mov al,bh
Call display
Int 20
Display Subroutine:
mov bl,al ;         Save original number and al,f0 ;Force bits 0-3 low
mov cl,4 ;           Four rotates
ror al,cl ;             Rotate MSD into LSD
add al,30 ;          Convert to ASCII
mov ah,0e ;       BIOS video service 0E
int 10 ;                Display character
mov al,bl ;          Recover original number
and al,0f ;           Force bits 4-7 low
add al,30 ;          Convert to ASCII
int 10 ;                 Display character
ret ;                      Return to calling program
                                                   ;
                                                             ;Input buffer begins here

No comments:

Post a Comment