将 1 个字节的立即数添加到 2 个字节的内存位置 [英] add 1 byte immediate value to a 2 bytes memory location
问题描述
来自
注意我突出显示的两条说明.
我在 NASM 中尝试了以下代码(符合第一条突出显示的指令):
添加 WORD [myvar], BYTE 0xA5
但我收到以下错误:
<块引用>警告:有符号字节值超出范围
我做错了什么?
8 位立即数操作数(这里用 imm8
表示)被符号扩展为 16(或 32)位以匹配另一个操作数的大小(分别为 r/m16
或 r/m32
).
因此,只能表示 -128 到 127 之间的值,这就是您从汇编程序收到此警告的原因.
对于值 0xA5,您需要使用 WORD
立即数 (imm16
):
添加 WORD [myvar], WORD 0xA5
(尽管 WORD
在源操作数上是可选的,因为常量的大小暗示了它).
The add
instruction documentation from this page says the following:
Notice the two instructions that I highlighted.
I tried the following code in NASM (which conforms with the first highlighted instruction):
add WORD [myvar], BYTE 0xA5
But I got the following error:
warning: signed byte value exceeds bounds
What am I doing wrong?
The 8-bit immediate operand (denoted here by imm8
) is sign-extended into 16 (or 32) bits to match the size of the other operand (r/m16
or r/m32
, respectively).
Thus, only values between -128 and 127 can be represented, which is why you receive this warning from the assembler.
For the value 0xA5, you need to use a WORD
immediate (imm16
):
add WORD [myvar], WORD 0xA5
(although the WORD
is optional on the source operand, since it is implied by the constant's size).
这篇关于将 1 个字节的立即数添加到 2 个字节的内存位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!