汇编语言,如何从键盘输入数字并输出,遇符号或字母输出error

2025-01-07 04:45:06
推荐回答(2个)
回答1:

;已测试,你看看是否完全符合你的要求
.386
RW MACRO A,B
LEA DX, A
MOV AH, B
INT 21H
ENDM
DATA SEGMENT USE16
BUF DB 200 DUP(?)
STR1 DB 'ERROR$'
STR2 DB 0DH,0AH,'$'
DATA ENDS
STACK SEGMENT USE16 STACK
DB 200 DUP(0)
STACK ENDS
CODE SEGMENT USE16
ASSUME CS:CODE, DS:DATA, SS:STACK
START:
MOV AX, DATA
MOV DS, AX
XOR DI, DI
L1: MOV AH, 1
INT 21H
CMP AL, 0DH
JE J1
CMP AL, '0'
JB J2
CMP AL, '9'
JA J2
MOV BUF[DI],AL
INC DI
JMP L1
J1: MOV BUF[DI],'$'
LEA DX, STR2
MOV AH, 9
INT 21H
LEA DX, BUF
MOV AH, 9
INT 21H
JMP EXIT
J2: LEA DX, STR2
MOV AH, 9
INT 21H
LEA DX, STR1
MOV AH, 9
INT 21H
EXIT: MOV AH, 4CH
INT 21H
CODE ENDS
END START

回答2:

婚了