A2032:寄存器使用无效

A2032: Invalid use of register

我有一行汇编如下:

mov target[sizeof source - ecx],byte ptr ebx

但是,我遇到了错误 A2032: Invalid use of register

据我所知,我没有做错任何事,但显然我做错了。

如有任何帮助,我们将不胜感激。

两个错误:

汇编程序不知道 byte ptr ebx 是什么,处理器不能减去 ECX(它只能加)。

我想,下面的序列可以满足您的要求:

neg ecx                              ; Change sign
mov target[sizeof source + ecx], bl
neg ecx                              ; Restore ECX (if needed)

如果您尝试存储单个字节(即操作数大小 = 8 位的 mov),则 byte ptr 位于地址之前,而不是寄存器之前。

mov byte ptr [base + constant + ecx], bl  ;  bl is the low byte of ebx

assembler 负责在 assemble 时将 target + sizeof source 添加到单个位移中以编码为机器代码。至于指令编码,它只是一个寄存器的偏移量,无论常量或寄存器是否有"the pointer"或"the array index"。

offset1[offset2 + reg] 看起来很不寻常,并且可能不适用于英特尔语法的所有变体。 (这让我想起了 AT&T 的语法是 offset(%ecx),其中偏移量可以是任何 assemble-时间常数的总和)。


The diagram in the x86 wikipedia article, shows which byte registers are subsets of which larger registers. It's kind of cluttered; I think I've seen better diagrams somewhere else. Maybe some of the other links in https://whosebug.com/tags/x86/info 会有帮助。

无论如何,如果你想把ebx的低字节存放在[target + source - ecx],你需要先取反ecx。 rkhb 的回答看起来不错。

您评论说

mov bl,cl

有点帮助。这似乎很奇怪。您现在存储的是地址偏移量的低字节,而不是之前 ebx 中的低字节。