1

当我尝试构建此代码时出现此错误:

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

当我尝试从中减去ml1337skillz并将usPop结果存储到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
4

1 回答 1

6

这两行是你的问题:

sub eax,my1337Sk1LLz    ;subtracts 1337h from usPop in eax
mov Difference, eax     ;stores eax into Difference

eax是 32 位,但两者my1337Sk1LLz都是Difference16 位。

有两种方法可以解决这个问题:

  1. 改变 和 的my1337Sk1LLz大小Difference现在,您分别拥有 asWORD和类型SWORD。您可以将它们更改为32 位DWORDSDWORD使其成为 32 位。

  2. 零扩展和截断。你需要另一个寄存器。我会使用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然后你可以存储into的低位词Difference,丢弃高位词:

    mov Difference, ax
    
于 2013-04-29T02:14:43.547 回答