这段汇编代码是否无效? [英] Is this piece of assembly code invalid?
问题描述
我正在尝试确定以下汇编代码是否无效。
I'm trying to figure out whether the following piece of assembly code is invalid.
movb $0xF, (%bl)
是否无效?如果是这样,为什么?谢谢。
Is it invalid? If so, why? Thanks.
推荐答案
您没有说什么处理器。 bl
至少在x86处理器中是8位寄存器,但不能用于寻址。
You don't say what processor. bl
is a 8-bit register at least in x86 processors, but it cannot be used for addressing.
为什么它是无效指令吗?嗯,汇编指令无效的原因是给定处理器没有这样的指令。没有可能对该指令进行编码。在这种情况下(假设x86),使用 bl
或任何其他8位寄存器都不进行寻址就没有必要了。在16位代码中,只有16位寄存器 bx
, bp
, si
和 di
可以用于内存寻址。 维基百科提供了所有可能的寻址模式的有用列表(请注意,它使用的是Intel语法,您的代码使用AT& T语法)。
Why is it invalid instruction? Well, the reason an assembly instruction is invalid is that there's no such instruction for the given processor. There is no possible way to encode this instruction. In this case (assuming x86), using bl
or any other 8-bit register neither for addressing has not been considered necessary. In 16-bit code only 16-bit registers bx
, bp
, si
and di
can be used for memory addressing. Wikipedia has a useful list of all possible addressing modes (please do note it's using Intel syntax, your code is in AT&T syntax).
编辑:在AT& T语法中,字母 b <
movb
中的/ code>定义它处理8位操作数。
In AT&T syntax the letter b
in movb
defines it deals with an 8-bit operand.
要获取更多或减去您的目标(使用 bl
进行寻址),您可以执行以下操作之一(这些使用Intel YASM / NASM语法,包括GNU <$ c $在内的MASM样式的汇编器c> .intel_syntax noprefix 想要 byte ptr
):
To obtain more or less your goal (to use bl
for addressing), you could do one of these (these are in Intel YASM/NASM syntax, MASM-style assemblers including GNU .intel_syntax noprefix
want byte ptr
):
对于16位代码:
xor bh,bh
mov byte [bx], 0x0f
对于32位代码:
movzx ebx,bl
mov byte [ebx], 0x0f
对于64位代码:
movzx ebx,bl ; with implicit zero-extension to 64-bit
mov byte [rbx], 0x0f
很少有人想将任何内容存储到0..255(一个字节)的线性地址中。在64位模式下,通常禁用分段功能,因此DS基数固定为0,这绝对是指令的工作,但是特别是在16位模式下,DS基数可能非零。
It's rare that you ever want to store anything to a linear address from 0..255 (one byte). In 64-bit mode where segmentation is mostly disabled so the DS base is fixed at 0, this is definitely what the instruction is doing, but especially in 16-bit mode, the DS base could be non-zero.
这篇关于这段汇编代码是否无效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!