任务是从用户那里获得一位输入并输出1-2位。我不知道为什么它不起作用 1digit + 1digit =1 digit 以及为什么有时它适用于 1digit + 1digit = 2 digit 但有时它不会。它还包括减法、乘法、除法和模运算。
标题
;-----------------------------------------------------
.MODEL SMALL
.STACK 64
.DATA
INPUT DB 13, 10, "Enter input : ","$"
SUM DB 13,10, "The sum is : ","$"
DIFF DB 13,10, "The difference is : ","$"
MULTI DB 13,10, "The product is : ","$"
DIVI DB 13,10, "The quotient is : ","$"
MODULO DB 13,10, "The modulo is : ","$"
NUM1 db ?
NUM2 db ?
OP db ?
RES db ?
;-----------------------------------------------------
.CODE
MAIN PROC NEAR
MOV AX,@DATA
MOV DS,AX
; outputs "input" message
LEA DX, INPUT
MOV AH, 09h
INT 21h
; get first input
MOV AH, 01h
INT 21h
SUB AL, '0'
MOV NUM1, AL
; get operand
MOV AH, 01h
INT 21h
MOV OP, AL
; get second input
MOV AH, 01h
INT 21h
SUB AL, '0'
MOV NUM2, AL
CMP OP, "+"
JE @ADD
CMP OP, "-"
JE @SUB
CMP OP, "*"
JE @MULTIPLY
CMP OP, "/"
JE @DIVIDE
CMP OP, "%"
JE @MOD
@ADD :
ADD AL, NUM1
MOV RES, AL
LEA DX, SUM
MOV AH, 09h
INT 21h
JMP @PRINT
@SUB :
MOV AL, NUM1
CMP AL, NUM2
JG @WITHOUTNEG
JMP @WITHNEG
@WITHNEG :
MOV AL, NUM2
SUB AL, NUM1
MOV RES, AL
LEA DX, DIFF
MOV AH, 09h
INT 21h
MOV OP, "-"
MOV DL, OP
MOV AH,02h
INT 21h
JMP @PRINT
@WITHOUTNEG :
MOV AL, NUM1
SUB AL, NUM2
MOV RES, AL
LEA DX, DIFF
MOV AH, 09h
INT 21h
JMP @PRINT
@MULTIPLY :
MOV AL, NUM1
IMUL NUM2
MOV RES, AL
LEA DX, MULTI
MOV AH, 09h
INT 21h
JMP @PRINT
@DIVIDE :
XOR AX, AX
MOV AL, NUM1
IDIV NUM2
MOV RES, AL
LEA DX, DIVI
MOV AH, 09h
INT 21h
JMP @PRINT
@MOD :
XOR AX, AX
MOV AL, NUM1
IDIV NUM2
MOV RES, AH
LEA DX, MODULO
MOV AH, 09h
INT 21h
JMP @PRINT
@PRINT :
XOR AX, AX
MOV AL, RES
MOV BL, 10
IDIV BL
ADD AL, '0'
MOV DL, AL
MOV AH,02h
INT 21h
ADD AH, '0'
MOV DL, AH
MOV AH,02h
INT 21h
JMP @EXIT
@EXIT :
MOV AH,4Ch
INT 21h
MAIN ENDP
;----------------------------------------------------------------
END MAIN