;两个数相加,输出结果
assume cs:code,ds:data,ss:stack
data segment
n1 db 1,2,3,4,5,1,1,0,0dh ;被加数
n2 db 1,2,3,4,5,1,1,0,0dH ;加数
sum db 20 dup(0) ;结果
data ends
stack segment
z dw 16 dup(0)
stack ends
code segment
start:
mov ax,data ;数据段
mov ds,ax
mov ax,0b872h ;确定显示位置
mov es,ax
mov ax,stack ;确定栈段
mov ss,ax
mov sp,32
mov cx,0
mov bx,0
a:
mov al,n1[bx]
cmp al,0d
jz a1
inc cx
inc bx
jmp a
a1:
mov ax,cx
mov di,cx
dec di
mov bx,di
mov bx,di
mov cl,2
div cl
mov cl,al
mov ch,0
mov si,0
a2:
mov al,n1[si]
mov ah,n1[di]
mov n1[si],ah
mov n1[di],al
mov al,n2[si]
mov ah,n2[di]
mov n2[si],ah
mov n2[di],al
inc si
dec di
loop a2
mov di,10H
mov bx,0
mov cx,0
clc ;清除进位标志位
s:
mov al,n1[bx]
mov dl,n2[bx]
;判断al是否等于0
cmp al,0dH
;al的结果不为0就进行运算
jnz s1
mov ax,4c00h
int 21h
s1:
;相加
add al,dl
;是否大于9
cmp al,10
jns s3
s4:
add al,30h
mov es:[di],al
mov byte ptr es:[di+1],03h
inc bx
sub di,2
jmp s
s3:
sub al,10
js s5
s6: add byte ptr n1[bx+1],1
jmp s4
s5:
mov al,9
jmp s6
code ends
end start