我想在内存位置添加一个字节到32位寄存器,
这在x86组装中是否可行?
add edx, byte [ebx]
导致error: mismatch in operand sizes
答案 0 :(得分:5)
您需要确保操作数大小相同。
这涉及到标志的问题。如果您使用已签名的整数,则应使用movsx,或者如果您使用无符号整数,则使用movzx。
movsx/movzx eax, byte ptr [ebx]
add edx, eax
答案 1 :(得分:0)
第一个操作数是寄存器或内存而第二个操作数是立即数是可能的。
Opcode |Instruction | Description
83 /0 ib |ADD r/m32, imm8 | Add sign-extended imm8 to r/m32.
from here https://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-instruction-set-reference-manual-325383.pdf