程序集获取输入 - 使用StdIn的无效指令操作数

时间:2012-08-20 07:02:33

标签: assembly x86 masm32

我正在制作一个程序来练习获取输入和算术,当将用户的输入存储在缓冲区然后用它们进行算术运算时,我得到错误A2070 - 无效的指令操作数。这是我的代码:

include C:\masm32\include\masm32rt.inc

.data
msg     db "Enter a number: ", 0
msg2    db "Enter another number: ",13,10,0
msg3    db "Your numbers: ", 13,10,0
msg4    db "Added = ", 0
spacer  db " ",13,10,0
msg5    db "Subtracted = ", 0
msg6    db "Multiplied = ", 0

ansadd  sdword 0
anstake sdword 0
ansmul  sdword 0

.data?
buffer1 db 12 dup(?)
buffer2 db 12 dup(?)



.code
start:
lea eax, msg
push eax
call StdOut

push 100
push buffer1             ;line 29
call StdIn

xor eax, eax

lea eax, msg2
push eax    
call StdOut

push 100
push buffer2             ;line 39
call StdIn

xor eax, eax

lea eax, buffer1
lea ebx, buffer2
add eax, ebx
push eax
pop ansadd

lea eax, buffer1
lea ebx, buffer2
sub eax, ebx
push eax
pop anstake

xor ebx, ebx
lea eax, buffer1
lea ecx, buffer2
mul eax
push eax
pop ansmul

xor eax, eax
xor ebx, ebx
xor ecx, ecx

lea eax, msg3
push eax 
call StdOut

lea eax, msg4
push eax
call StdOut

lea eax, ansadd
push eax
call StdOut

lea eax, msg5
push eax
call StdOut

lea eax, anstake
push eax
call StdOut

lea eax, msg6
push eax
call StdOut

lea eax, ansmul
push eax
call StdOut

push 0
call ExitProcess
END start

以下是MASM ml.exe的反馈:

test.asm(29) - A2070 - Invalid instruction operands.
test.asm(39) - A2070 - Invalid instruction operands.

变量有什么问题?我怀疑它可能是变量声明。

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

你应该推送buffer1的地址 - 完全按推送mgs和mgs2的地址...

而不是

push buffer1

DO

lea eax, buffer1
push eax