我用汇编代码编写了一个简单的程序(打开控制台并循环输入,直到用户输入为止5
)。我想将每个输入存储在变量中input
(新输入将覆盖旧输入)。这是我的代码:
format PE console
entry start
include 'win32a.inc'
;======================================
section '.data' data readable writeable
;======================================
input db "", 0
;=======================================
section '.code' code readable executable
;=======================================
start:
ccall [getchar] ; Wait for input
cmp eax, "5" ; Compare input with string
je exit ; If it is equal, then exit
jne start ; If not, wait for input again
exit:
stdcall [ExitProcess], 0
;====================================
section '.idata' import data readable
;====================================
library kernel,'kernel32.dll',\
msvcrt,'msvcrt.dll'
import kernel,\
ExitProcess,'ExitProcess'
import msvcrt,\
printf,'printf',\
getchar,'_fgetchar'
我试图写
ccall [getchar] ; Wait for inout
cmp eax, "5" ; Compare input with string
mov [input], eax ; This line is added
je exit ; If it is equal, then exit
jne start ; If not, wait for input again
但是我出错了Operand sizes do not match.
。我已经搜索了此错误,但没有发现任何有用的信息。
该eax
寄存器是32位(4字节)寄存器,但是的数据类型input
为字节。
您需要双字数据来存储32位值:
input dd 0
注意:输入的数据eax
实际上不是字符串。与之比较时"5"
,该值"5"
将转换为32位值,即0x00000005
。声明input
为零长度字符串不仅会使类型错误,而且太小而无法容纳4字节值,因为它只有1字节大(字符串终止符)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句