我刚刚开始学习汇编语言,我尝试用notepad++和dosbox模拟器自己编写一个程序来进行乘法运算。然而,结果总是随机符号,与我预期的答案不符。
这是我编写的完整代码
.model small
.stack
.data
msg1 DB "Quantity (unit): $"
msg2 DB 13,10,"Unit price (RM): $"
msg3 DB 13,10,"Total amount is RM$"
Quantity DB 0
Unit_price DB 0
Total DB 0
.code
main proc
mov AX,@data
mov DS, AX
mov AH, 09h ;display 1st msg
lea DX, msg1
int 21h
mov AH, 01h
mov Quantity, AL
int 21h
mov AH, 09h ;display 2nd msg
lea DX, msg2
int 21h
mov AH, 01h
mov Unit_price, AL
int 21h
mov AX, 0
sub Quantity, '0'
sub Unit_price, '0'
mov AL, Quantity
mul Unit_price
add Total, AL
add Total, '0'
mov AH, 09h
lea DX, msg3
int 21h
mov AH, 02h
mov DL, Total
int 21h
mov AX, 4C00H
int 21h
MAIN ENDP
END MAIN
图片是我2和3相乘得到的结果(应该是6,但不知道为什么是一个箭头)
你写道:
mov AH, 01h
mov Quantity, AL
int 21h
读取的字符由 AL
服务在
int 21h
中返回,因此
mov Quantity, AL
需要在之后 int 21h
出现。