将变量与寄存器一起使用:错误A2022:指令操作数的大小必须相同 [英] Using variable with register: error A2022: instruction operands must be the same size
本文介绍了将变量与寄存器一起使用:错误A2022:指令操作数的大小必须相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试构建此代码时遇到此错误:
1>------ Build started: Project: Project, Configuration: Debug Win32 ------
1> Assembling [Inputs]...
1>assign2.asm(12): error A2022: instruction operands must be the same size
1>assign2.asm(13): error A2022: instruction operands must be the same size
当我尝试从usPop
中减去ml1337skillz
并将结果存储到Difference
中时,会发生这种情况。我正在使用eax
作为它的临时寄存器。
TITLE Learning (learning.asm)
INCLUDE Irvine32.inc
.data
usPop DWORD 313900000d ; 32-bit
my1337Sk1LLz WORD 1337h ; 16-bit
Difference SWORD ? ; 16-bit
.code
main PROC
FillRegs:
mov eax,usPop ;load 3139000000d into eax ; fine
sub eax,my1337Sk1LLz ;subtracts 1337h from usPop in eax ; error #1
mov Difference, eax ;stores eax into Difference ; error #2
call DumpRegs ;shows Registers
exit ;exits
main ENDP
END main
推荐答案
这两行是您的问题:
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
这篇关于将变量与寄存器一起使用:错误A2022:指令操作数的大小必须相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文