【发布时间】:2015-04-25 12:10:16
【问题描述】:
我用汇编代码编写了一个简单的程序(打开控制台并循环输入,直到用户输入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.。我已经搜索过这个错误,但没有找到任何有用的东西。
【问题讨论】:
-
mov [input], eax是一个 4 字节的值移动(eax的大小),但input是一个db(字节)。试试mov [input], al(移动eax的低字节)。
标签: assembly