print macro msg
lea dx,msg
mov ah,09h
int 21h
endm
read macro msg1,l1,j1
xor cx,cx
mov si,offset msg1
l1: mov ah,01
int 21h
cmp al,0dh
je j1
sub ax,30h
mov [si],al
inc si
inc cx
jmp l1
j1: nop
endm
printnum macro msg2,msg3,l2
xor cx,cx
mov cx,msg3
mov si,offset msg2
mov al,[si]
cmp al,00
jne l2
inc si
dec cx
l2: mov dl,[si]
add dl,30h
mov ah,02h
int 21h
inc si
loop l2
endm
.model small
.stack 100h
.data
str1 db 10,13,'Enter a number(BCD) $'
str2 db 10,13,'Sum(BCD): $'
num1 db 20 dup(0)
num2 db 20 dup(0)
sum db 20 dup(0)
len1 dw 0
len2 dw 0
len3 dw 0
.code
mov ax,@data
mov ds,ax
print str1
read num1,loop1,jump1
mov len1,cx
print str1
read num2,loop2,jump2
mov len2,cx
mov si,len1
mov di,len2
mov ax,len1
cmp ax,len2
jc jump3
mov bx,len1
mov cx,len2
jmp jump4
jump3: mov bx,len2
mov cx,len1
jump4: inc bx
mov len3,bx
clc
loop3: dec si
dec di
dec bx
mov al,num1[si]
adc al,num2[di]
aaa
mov sum[bx],al
loop loop3
mov al,00
rcl al,01
mov cx,si
cmp cx,00
je jump5
rcr al,01
loop4: dec si
dec bx
mov al,num1[si]
adc al,00
aaa
mov sum[bx],al
loop loop4
jmp jump6
jump5: mov cx,di
cmp cx,00
je jump7
rcr al,01
loop5: dec di
dec bx
mov al,num2[di]
adc al,00
aaa
mov sum[bx],al
loop loop5
jump6: mov al,00
rcl al,01
jump7: dec bx
mov sum[bx],al
print str2
printnum sum,len3,loop6
mov ah,4ch
int 21h
end
No comments:
Post a Comment