Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 894
JAW1025 Avatar asked Feb 04 '12 00:02

JAW1025


People also ask

How many general purpose registers are there in a 32-bit x86 CPU?

The x86 architecture has 8 General-Purpose Registers (GPR), 6 Segment Registers, 1 Flags Register and an Instruction Pointer.

What is x86 register?

The main tools to write programs in x86 assembly are the processor registers. The registers are like variables built in the processor. Using registers instead of memory to store values makes the process faster and cleaner.

Are registers 32 bits?

A register is a part of the processor that can hold a bit pattern. On the MIPS, a register holds 32 bits. There are many registers in the processor, but only some of them are visible in assembly language. The others are used by the processor in carrying out its operations.

How many bits is a x86 instruction?

The x86 is developed based on the Intel 8086 microprocessor and its 8088 variant where it started out as a 16-bit instruction set for 16-bit processors where many additions and extensions have been added to the x86 where it grew to 32-bit instruction sets over the years with almost entirely full backward compatibility.


1 Answers

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.

like image 159
Daniel Kamil Kozar Avatar answered Sep 22 '22 20:09

Daniel Kamil Kozar