用汇编语言编一个加法程序

2024-12-25 09:26:40
推荐回答(1个)
回答1:

;输入格式必须为A+或-或/或*B=
;按回车结束运算数为(0~255)
DATAS SEGMENT
x db 20 dup(?)
y db 'chu cuo le','$'
DATAS ENDS

CODES SEGMENT
ASSUME CS:CODES,DS:DATAS
START:
MOV AX,DATAS
MOV DS,AX
JMP A
KAISHI:
;回车换行
MOV DL,0DH
MOV AH,02H
INT 21H
MOV DL,0AH
INT 21H
LEA SI,X
SUB AX,AX
SUB BX,BX
SUB CX,CX
SUB DX,DX
;输入数字
A: MOV AH,01H
INT 21H
CMP AL,0DH
JZ L
CMP AL,30H
JB B
CMP AL,3AH
JNB F
SUB AL,30H
MOV CH,AL
MOV AL,BL
MOV BL,0AH
MUL BL
ADD AL,CH
MOV BL,AL
JMP A
;判断+-*/=
B: CMP AL,2BH
JNZ K
MOV X[SI],BL
INC SI
MOV CL,0H
AND BL,0
JMP A
K: CMP AL,2DH
JNZ D
MOV X[SI],BL
INC SI
MOV CL,01H
AND BL,0
JMP A
D: CMP AL,2AH
JNZ E
MOV X[SI],BL
INC SI
MOV CL,02H
AND BL,0
JMP A
E: CMP AL,2FH
JNZ T
MOV X[SI],BL
INC SI
MOV CL,03H
AND BL,0
JMP A
;计算
F: MOV [SI],BL
CMP AL,3DH
JNZ T
LEA SI,X
MOV AL,X[SI]
INC SI
MOV BL,X[SI]
CMP CL,0
JNZ G
ADD AL,BL
JMP J
G: CMP CL,01H
JNZ H
SUB AL,BL
JMP J
H: CMP CL,02H
JNZ I
AND AH,0
MUL BL
JMP J
I: AND AH,0
CMP CL,03H
DIV BL
;输出
J: AND AH,0
CMP AL,100
JB ER
MOV BL,100
DIV BL
MOV CL,AH
ADD AL,30H
MOV DL,AL
MOV AH,02H
INT 21H
MOV AL,CL
ER: CMP AL,10
JB YI
MOV BL,10
AND AH,0
DIV BL
ADD AL,30H
MOV DL,AL
MOV CL,AH
MOV AH,02H
INT 21H
MOV AL,CL
YI: ADD AL,30H
MOV DL,AL
MOV AH,02H
INT 21H
JMP KAISHI
T: LEA DX,Y
MOV AH,09H
INT 21H
JMP KAISHI
L: MOV AH,4CH
INT 21H
CODES ENDS
END START