📄 66.asm
字号:
MyStack segment stack
dw 64 dup(?)
MyStack ends
data segment
string db 8,?,9 dup(?);接受输入
string_1 db 8 dup(?);加数
sum db 8 dup(?) ;被加数及结果
bx_first dw 0;保护string_1的地址
bx_second dw 0; 保护sum的地址
first_bit db 0;第一个操作的位数
second_bit db 0 ;第二个操作的位数
data ends
code segment
assume ds:data,cs:code,ss:MyStack
start:
mov ax,data
mov ds,ax
mov es,ax
call READ;读入第一个数
;存入被加数
Lea di,string_1
add di,7
Lea si,string
xor cx,cx
mov CL,string+1
add si,cx
inc si
mov first_bit,CL
std
rep movsb
call READ;读入第二个数
; mov ah,string+4;回车要用一个单元存
;存入加数
Lea di,sum
add di,7
Lea si,string
xor cx,cx
mov CL,string+1
add si,cx
inc si
mov second_bit,CL
std
rep movsb
;;;;;;;;;;;;;;;;;;实现加法操作;;;;;;;;;;;;;;;;;;;
;末尾数相加
Lea bx,string_1
add bx,7
mov DL,[bx]
dec bx
mov bx_first,bx
Lea bx,sum
add bx,7
add [bx],DL
dec bx
mov bx_second,bx
xor cx,cx
mov CL,first_bit
cmp CL,second_bit
jc Lab_1 ;first_bit<second_bit
jmp Lab_2
Lab_1:
mov CL,second_bit
Lab_2:
cmp CL,1
jz Lab_end
dec CL
;执行带进位的加法
Addition:
mov bx,bx_first
mov DL,[bx]
dec bx
mov bx_first,bx
mov bx,bx_second
adc [bx],DL
dec bx
mov bx_second,bx
loop Addition
Lab_end:
;当最高位有进位时不会丢失
mov bx,bx_second
mov DL,0
adc [bx],DL
call WRITE
jmp Lab_Over
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;子程序1:实现接受字符串输入,并将其转换成相应的十进制数
READ proc near
push ax
push bx
push cx
push dx
;;将string从第2位起清零
mov AL,0
Lea di,string
inc di
xor cx,cx
mov CL,10d
cld
rep stosb ;;;默认操作数AL→[di]
;;输入字符
Lea dx,string
mov ah,0ah
int 21h
;;字符转数字
Lea bx,string
add bx,2;从第三个字符开始
xor cx,cx
mov CL,string+1;设定循环次数
change:
sub byte ptr [bx],30h
inc bx
loop change
mov ah,2
mov DL,0ah
int 21h
mov DL,0dh
int 21h
pop dx
pop cx
pop bx
pop ax
ret
READ endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;子程序2: 实现十六进制数转换成十进制数输出
WRITE proc near
push ax
push bx
push cx
push dx
;;为实现从后往前计算,将基址寄存器指向sum的最后一个元素
Lea bx,sum
add bx,7
mov DL,9
mov DH,1
xor cx,cx
mov CL,8
clc
;将大于9的部分转化成相应的十进制数
next:
cmp DL,[bx]
jc change_1
jmp over
change_1:
sub [bx],DL
sub [bx],DH;[bx]-10d
adc [bx-1],DH;前一位加1
over:
dec bx
loop next
Lea bx,sum
xor cx,cx
mov CL,8
;;输出结果
Out_Put:
mov ah,2
mov DL,[bx]
add DL,30h
inc bx
int 21h
loop Out_Put
pop dx
pop cx
pop bx
pop ax
ret
WRITE endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Lab_Over:
mov ah,4ch
int 21h
code ends
end start
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -