从 64 位地址加载到其他寄存器而不是 rax [英] Load from a 64-bit address into other register than rax
问题描述
在 x64 上,从 64 位绝对地址加载(即取消引用 64 位立即数)可以通过
On x64, loading from a 64-bit absolute address (that is, dereferencing a 64-bit immediate) can be done by
movabs addr64, %rax
但是,当目标寄存器不是 rax
时,汇编器会给出一条错误消息,指出 movabs 的操作数大小不匹配
.我错过了什么?
However, when the destination register is any other than rax
the assembler gives an error message saying operand size mismatch for movabs
. What am I missing?
推荐答案
来自MOV说明文档您可以看到您可以将 64 位立即移动到任何寄存器,但加载/存储涉及 64 位立即绝对地址 只能与 Areg 一起使用
From the MOV instruction document you can see that you can move a 64-bit immediate to any registers, but loads/stores involving a 64-bit immediate absolute address can only work with Areg
操作码 | 说明 | 说明 |
---|---|---|
A0 | MOV AL,moffs8* | 将 (seg:offset) 处的字节移动到 AL. |
REX.W + A0 | MOV AL,moffs8* | 将 (offset) 处的字节移动到 AL. |
A1 | MOV AX,moffs16* | 将 (seg:offset) 处的单词移至 AX. |
A1 | MOV EAX,moffs32* | 将 (seg:offset) 处的双字移动到 EAX. |
REX.W + A1 | MOV RAX,moffs64* | 将位于 (offset) 处的四字移动到 RAX. |
A2 | MOV moffs8,AL | 将 AL 移动到 (seg:offset). |
REX.W + A2 | MOV moffs8***,AL | 将 AL 移动到 (偏移). |
A3 | MOV moffs16*,AX | 将 AX 移动到 (seg:offset). |
A3 | MOV moffs32*,EAX | 将 EAX 移动到 (seg:offset). |
REX.W + A3 | MOV moffs64*,RAX | 将 RAX 移动到(偏移量). |
Opcode | Instruction | Description |
---|---|---|
A0 | MOV AL,moffs8* | Move byte at (seg:offset) to AL. |
REX.W + A0 | MOV AL,moffs8* | Move byte at (offset) to AL. |
A1 | MOV AX,moffs16* | Move word at (seg:offset) to AX. |
A1 | MOV EAX,moffs32* | Move doubleword at (seg:offset) to EAX. |
REX.W + A1 | MOV RAX,moffs64* | Move quadword at (offset) to RAX. |
A2 | MOV moffs8,AL | Move AL to (seg:offset). |
REX.W + A2 | MOV moffs8***,AL | Move AL to (offset). |
A3 | MOV moffs16*,AX | Move AX to (seg:offset). |
A3 | MOV moffs32*,EAX | Move EAX to (seg:offset). |
REX.W + A3 | MOV moffs64*,RAX | Move RAX to (offset). |
如您所见,没有用于对寄存器编号进行编码的 ModR/M 字节.由于这比将 64 位立即数移动到寄存器更不常用,因此不会有问题.如果确实需要,可以在 2 条指令中完成
As you can see there's no ModR/M byte to encode the register number. Since this is less commonly used than moving a 64-bit immediate to a register it won't be a problem. If really needed it can be done in 2 instructions
MOVABS
是 MOV
操作码形式 MOV Areg, [Offs64]
和 MOV [Offs64] 的 GAS 操作码名称,注册
.在 Yasm 的 NASM 语法模式下,你可以通过说 MOV AX, [qword xxx]
来获得这种形式.Yasm 的 GAS 语法模式接受 MOVABS
(为了 GAS 兼容性).请注意,此表格仅适用于以 Areg (AL/AX/EAX/RAX) 作为源/目标寄存器的情况.
MOVABS
is the GAS opcode name for theMOV
opcode formsMOV Areg, [Offs64]
andMOV [Offs64], Areg
. In Yasm's NASM syntax mode, you can get this form by sayingMOV AX, [qword xxx]
. Yasm's GAS syntax mode acceptsMOVABS
(for GAS compatibility). Note this form is only valid with Areg (AL/AX/EAX/RAX) as the source/destination register.
http://cvs.tortall.net/pipermail/yasm-devel/2006-March/000579.html
这篇关于从 64 位地址加载到其他寄存器而不是 rax的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!