所以我只在大会上写了几个星期,我在使用.if语句时遇到了这个问题。
我的程序应该是一个简单的16位计算器,加,减,除和乘,只需要几个异常处理硬编码。那将是除以0,溢出/下溢。
问题是,由于某些原因我改变了变量值,即使0被更改和插入也不合适。
例如:
.if pick == 1
INVOKE printf, ADDR oStrFmt, ADDR msg8
INVOKE scanf, ADDR ioDecFmt, ADDR num
mov ax, current
add ax, num
mov current, ax
mov error, 0
正在将我的msg0更改为= \ 0
在我修改一些代码之前,它将12506移动到错误而不是0。
不确定为什么会发生这种情况,并且可以使用一些帮助,因为我还没能确定我将发布整个代码的位置。
.386
.model flat, c
.stack 100h
includelib libcmt.lib
includelib legacy_stdio_definitions.lib
printf PROTO arg1:Ptr Byte, printlist:VARARG
scanf PROTO arg2:Ptr Byte, inputlist:VARARG
system PROTO c:Dword
.data
oStrFmt byte 0Ah, "%s", 0
ioDecFmt byte 0Ah, "%d", 0
oCurrentFmt byte 0Ah, "%s %d", 0
oErrorFmt byte 0Ah, "%s %s", 0
error sword 0
current sword 0
pick sword 0
num sword 0
msg0 byte "Current value:", 0
msg1 byte "Error:", 0
msg2 byte "1. Add", 0
msg3 byte "2. Subtract", 0
msg4 byte "3. Multiply", 0
msg5 byte "4. Divide", 0
msg6 byte "5. Exit program", 0
msg7 byte "Please enter the number of the operation you would like to do: ", 0
msg8 byte "Please enter the number you would like to use in the equation: ", 0
errorMsg0 byte "None", 0
errorMsg1 byte "Division by Zero not allowed", 0
errorMsg2 byte "The number entered will cause overflow", 0
clearScr db 'cls', 0
.code
main proc
.while pick != 5
INVOKE system, ADDR clearScr
INVOKE printf, ADDR oCurrentFmt, ADDR msg0, current
.if error == 0
INVOKE printf, ADDR oErrorFmt, ADDR msg1, ADDR errorMsg0
.elseif error == 1
INVOKE printf, ADDR oErrorFmt, ADDR msg1, ADDR errorMsg1
.elseif error == 2
INVOKE printf, ADDR oErrorFmt, ADDR msg1, ADDR errorMsg2
.endif
INVOKE printf, ADDR oStrFmt, ADDR msg2
INVOKE printf, ADDR oStrFmt, ADDR msg3
INVOKE printf, ADDR oStrFmt, ADDR msg4
INVOKE printf, ADDR oStrFmt, ADDR msg5
INVOKE printf, ADDR oStrFmt, ADDR msg6
INVOKE printf, ADDR oStrFmt, ADDR msg7
INVOKE scanf, ADDR ioDecFmt, ADDR pick
.if pick == 1
INVOKE printf, ADDR oStrFmt, ADDR msg8
INVOKE scanf, ADDR ioDecFmt, ADDR num
mov ax, current
add ax, num
mov current, ax
mov error, 0
.elseif pick == 2
INVOKE printf, ADDR oStrFmt, ADDR msg8
INVOKE scanf, ADDR ioDecFmt, ADDR num
mov ax, current
sub ax, num
mov current, ax
mov error, 0
.elseif pick == 3
INVOKE printf, ADDR oStrFmt, ADDR msg8
INVOKE scanf, ADDR ioDecFmt, ADDR num
mov ax, current
imul num
mov current, ax
mov error, 0
.elseif pick == 4
INVOKE printf, ADDR oStrFmt, ADDR msg8
INVOKE scanf, ADDR ioDecFmt, ADDR num
.if num > 0
mov ax, current
idiv num
mov current, ax
mov error, 0
.endif
mov error, 1
.endif
.endw
ret
main endp
end
任何事都有帮助,非常感谢提前。