如何从汇编中的地址加载单个字节 [英] How to load a single byte from address in assembly

查看:107
本文介绍了如何从汇编中的地址加载单个字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从地址加载单个字节?我以为会是这样:

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位寄存器(和

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.

这篇关于如何从汇编中的地址加载单个字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆