AX、AH、AL 如何映射到 EAX? [英] How do AX, AH, AL map onto EAX?

查看:42
本文介绍了AX、AH、AL 如何映射到 EAX?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 x86 寄存器的理解是,每个寄存器都可以被整个 32 位代码访问,并且它被分成多个可访问的寄存器.

My understanding of x86 registers say that each register can be accessed by the entire 32 bit code and it is broken into multiple accessible registers.

在这个例子中 EAX 是一个 32 位寄存器,如果我们调用 AX 它应该返回前 16 位,如果我们调用 AH> 或 AL 应返回 16 位之后的下 8 位,AL 应返回最后 8 位.

In this example EAX being a 32 bit register, if we call AX it should return the first 16 bits, and if we call AH or AL it should return the next 8 bits after the 16 bits and AL should return the last 8 bits.

所以我的问题,因为我并不真正相信这就是它的运作方式.如果我们存储 32 位值又名 EAX 存储:

So my question, because I don't truly believe is this is how it operates. If we store the 32 bit value aka EAX storing:

0000 0100 0000 1000 0110 0000 0000 0111

所以如果我们访问 AX 它应该返回

So if we access AX it should return

0000 0100 0000 1000

如果我们读到AH,它应该返回

if we read AH it should return

0000 0100

当我们读取AL时,它应该返回

and when we read AL it should return

0000 0111

这是正确的吗?如果它是AH真正拥有的价值?

Is this correct? and if it is what value does AH truly hold?

推荐答案

不,这不太对.

EAX is the full 32-bit value
AX is the lower 16-bits
AL is the lower 8 bits
AH is the bits 8 through 15 (zero-based)

所以 AX 是由 AH:AL 两半组成的,它本身就是 EAX 的低半.(EAX 的上半部分不能作为 16 位寄存器直接访问;如果您想获得它,可以移位或旋转 EAX.)

So AX is composed of AH:AL halves, and is itself the low half of EAX. (The upper half of EAX isn't directly accessible as a 16-bit register; you can shift or rotate EAX if you want to get at it.)

为了完整起见,除了以上基于 32 位 CPU 的,64 位 Intel/AMD CPU 还具有

For completeness, in addition to the above, which was based on a 32-bit CPU, 64-bit Intel/AMD CPUs have

RAX, which hold a 64-bit value, and where EAX is mapped to the lower 32 bits.

所有这些也适用于 EBX/RBX、ECX/RCX 和 EDX/RDX.其他寄存器如 EDI/RDI 有一个 DI 低 16 位部分寄存器,但没有高 8 部分,低 8 DIL 只能在 64 位模式下访问:64 位架构中的汇编寄存器

All of this also applies to EBX/RBX, ECX/RCX, and EDX/RDX. The other registers like EDI/RDI have a DI low 16-bit partial register, but no high-8 part, and the low-8 DIL is only accessible in 64-bit mode: Assembly registers in 64-bit architecture

由于历史原因,在完整的 AX/EAX/RAX 中写入 AL、AH 或 AX 会保留其他字节未修改.例如,它必须将新的 AL 合并到完整的 RAX 中.(在 32 位或 64 位代码中,如果您不特别想要这种合并,则更喜欢 movzx eax, byte [mem]movzx eax, word [mem] load: 为什么 GCC 不使用部分寄存器?)

Writing AL, AH, or AX leaves other bytes unmodified in the full AX/EAX/RAX, for historical reasons. i.e. it has to merge a new AL into the full RAX, for example. (In 32 or 64-bit code, prefer a movzx eax, byte [mem] or movzx eax, word [mem] load if you don't specifically want this merging: Why doesn't GCC use partial registers?)

将 EAX 零扩展写入 RAX.(为什么 32 位寄存器上的 x86-64 指令将整个 64 位寄存器的上半部分归零?)

同样,所有这些都适用于每个寄存器,而不仅仅是 RAX.例如写入 DI 或 DIL 合并到旧的 RDI,写入 EDI 零扩展并覆盖完整的 RDI.R10B 或 R10W 写入合并相同,写入 R10D 使 R10 独立于旧的 R10 值.

Again, all of this applies to every register, not just RAX. e.g. writing DI or DIL merges into the old RDI, writing EDI zero-extends and overwrites the full RDI. Same for R10B or R10W writes merging, writing R10D leaving R10 independent of the old R10 value.

这篇关于AX、AH、AL 如何映射到 EAX?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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