如何从汇编中的地址加载单个字节
如何从地址加载单个字节?我认为这是这样的:
mov rax, byte[rdi]
How can I load a single byte from address? I thought it would be something like this:
mov rax, byte[rdi]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将一个字节合并到RAX的低字节中。
或更好的是,通过将零扩展到32位寄存器(和隐含于64位), movzx :
或者如果要签名 - extension到更宽的寄存器中,请使用 movsx 。
(在某些CPU上,MOVSX与Movzx一样有效,即使在负载端口中处理,甚至不需要Alu Uop。 uops.info
。代码>字节带有
byte ptr
。A
MOV
加载不需要大小指示符(al
目标>目标>代码>字节 operand-size)。movzx
始终为内存源做,因为32位目标不会在8个与16位内存源之间消除歧义。movzbl(%rdi),%eax
(用movzb指定我们零扩展一个字节,l指定32位目标大小。)Merge a byte into the low byte of RAX.
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:
Or if you want sign-extension into a wider register, use MOVSX.
(On some CPUs, MOVSX is just as efficient as MOVZX, handled right in a load port without even needing an ALU uop. https://uops.info. But there are some where MOVZX loads are cheaper than MOVSX, so prefer MOVZX if you don't care about the upper bytes and really just want to avoid partial-register shenanigans.)
The MASM equivalent replaces
byte
withbyte ptr
.A
mov
load doesn't need a size specifier (al
destination impliesbyte
operand-size).movzx
always does for a memory source because a 32-bit destination doesn't disambiguate between 8 vs. 16-bit memory sources.The AT&T equivalent is
movzbl (%rdi), %eax
(with movzb specifying that we zero-extend a byte, the l specifying 32-bit destination size.)