问题描述
如何从地址加载单个字节?我以为会是这样:
How can I load a single byte from address? I thought it would be something like this:
mov rax, byte[rdi]
推荐答案
mov al, [rdi]
将一个字节合并到RAX的低字节中.
Merge a byte into the low byte of RAX.
或者更好,通过零扩展到32位寄存器(和),并带有 MOVZX :
Or better, avoid a false dependency on the old value of RAX by zero-extending into a 32-bit register (and thus implicitly to 64 bits) with MOVZX:
movzx eax, byte [rdi] ; most efficient way to load one byte on modern x86
或者如果您想将符号扩展到更宽的寄存器中,请使用 MOVSX . (在某些CPU上,这和MOVZX一样有效.)
Or if you want sign-extension into a wider register, use MOVSX. (On some CPUs this is just as efficient as MOVZX.)
movsx eax, byte [rdi] ; sign extend to 32-bit, zero-extend to 64
movsx rax, byte [rdi] ; sign extend to 64-bit
MASM等效项将byte
替换为byte ptr
.
The MASM equivalent replaces byte
with byte ptr
.
mov
加载不需要大小说明符(al
目标暗含byte
操作数大小). movzx
始终对内存源起作用,因为32位目标不会在8位内存源与16位内存源之间产生歧义.
A mov
load doesn't need a size specifier (al
destination implies byte
operand-size). movzx
always does for a memory source because a 32-bit destination doesn't disambiguate between 8 vs. 16-bit memory sources.
这篇关于如何从汇编中的地址加载单个字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!