嘿所以我在运行此代码时收到此错误:
1>------ Build started: Project: Project, Configuration: Debug Win32 ------
1> Assembling [Inputs]...
1>assign2.asm(32): error A2022: instruction operands must be the same size
1>assign2.asm(33): error A2022: instruction operands must be the same size
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\BuildCustomizations\masm.targets(49,5):
error MSB3721: The command "ml.exe /c /nologo /Zi /Fo"Debug\assign2.obj" /Fl"Project.lst"
/I "c:\Irvine" /W3 /errorReport:prompt /Taassign2.asm" exited with code 1.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
以下代码,当我尝试从usPop中减去ml1337skillz并将结果存储到差异时,会发生这种情况。 (请记住,我刚刚开始学习这个领域:))
TITLE Learning (learning.asm)
INCLUDE Irvine32.inc
secondE = 00000000010001010000000000000000b
.data
myName BYTE "John Smith"
nameLen = ($ - myName)
nationalDebt QWORD 7975482431119.47d
usPop DWORD 313900000d
kindaNegative SDWORD -2147483648d
my1337Sk1LLz WORD 1337h
negUnit SBYTE -1
half BYTE 0.5d
Difference SWORD ?
starField BYTE 2000 DUP("*")
bigLoss SDWORD -50000
.code
main PROC
FillRegs:
mov eax,usPop ;store 3139000000d into eax
sub eax,my1337Sk1LLz ;subtracts 1337h from usPop in eax
mov Difference, eax ;stores eax into Difference
mov edx,bigLoss ;stores -50000 into edx
mov eax,secondE ;store 0E00 into eax
mov ah,'A' ;store string A into ah
mov al,'X' ;store string X into al
mov ebx,secondE ;store 0E00 into ebx
mov bh,'B' ;store string B into bh
mov bl,'X' ;store string X into bl
call DumpRegs ;shows Registers
exit ;exits
main ENDP
END main
答案 0 :(得分:3)
这两行是你的问题:
sub eax,my1337Sk1LLz ;subtracts 1337h from usPop in eax
mov Difference, eax ;stores eax into Difference
eax
是32位,但my1337Sk1LLz
和Difference
都是16位。
有两种方法可以解决这个问题:
更改my1337Sk1LLz
和Difference
的尺寸。现在您的类型分别为WORD
和SWORD
。您可以将这些更改为DWORD
和SDWORD
,使其成为32位。
零扩展和截断。您需要另一个注册。我将使用edx
,因为您似乎没有在那里使用它。首先,您需要签名my1337Sk1LLz
:
movzx edx, my1337Sk1LLz ; move, zero-extended, my1337Sk1LLz into EDX
然后你可以做减法:
sub eax, edx ; they're the same size now so we can do this
然后,您可以将eax
的低位词存储到Difference
中,弃用高位词:
mov Difference, ax