Search code examples
assemblyx86nasmcpu-registers32-bit

Intel x86 32-bit register confusion


I've been trying to learn 32-bit Intel x86 nasm syntax assembly on my Linux OS, and I've run into a question about the four general purpose 32-bit registers.

From what I've been thinking, eax was a 32-bit register that was supposed to be used with the 16-bit register ax, which was subdivided into ah (upper 8 bits), and al (lower 8 bits). And the same with ebx, ecx, and edx.

However after reading a quick article, I've become sort of confused.

Is the 32-bit register composed of the 16-bit register (which in turn is composed of the two 8-bit registers) with an additional 16-bits added on?

So far from what I've read on Google, all the results say is what they're used for, not their actual composition.


Solution

  • You are entirely correct. Four of the general purpose-registers EAX, EBX, ECX and EDX are composed as follows (I used the accumulator in the example) :

    1. Firstly, we have the lower byte and the upper byte of the 16-bit word. So, AX = AH || AL
    2. Then, we have the 16-bit extension of AX, which forms the dword. So, EAX = EAX(31:16) || AX.
    3. (in AMD64) The dword register is then extended to a qword register. Therefore, we have RAX = RAX(63:32) || EAX.

    The || operator is the concatenation operator. You should note that this rule does not apply to the other four general purpose registers, ESP, EBP, ESI and EDI.