Assembly Language (Intel x86) - Register Organization

Assembly Language (Intel x86) - Register Organization


                 Hello guys sorry for this late post but we had some electricity issue. Let's keep that issue aside and as I promised in this blog post we are going to see the register organization of the Intel x86 CPU.

What are registers and how it works?

  • Registers you often heard this thing and even learnt it into the school or college. But before jumping to the register lets talk about another thing called flip-flop.
  • According to the google, A flip-flop is a electronic circuit which has two stable states and used to store single bit binary information/data.
  • So a single flip-flop can store a single bit binary data means it can store either 0 or 1.
  • So the register is just a combination of multiple flip-flop.
                    1. A 8 bit register has 8 flip-flops.
                    2. A 16 bit register has 16 flip-flops.
                    3. A 32 bit register has 32 flip-flops.
                    4. A 64 bit register has 64 flip-flops.

  The reason why CPU are categorize into 32 bit (x86) and 64 bit (x86_64) because they have specific 32/64 bit register and 32/64 bit data bus which can carry 32/64 bit data at a time.

Now as I said in this post we are going to see the register organization of 32 bit CPU, so here it is.

Register Organization:-

Assembly language, reverse engineering, binary exploitation


Well as you can see in the diagram above,

A 32 bit CPU has,

                      * four general purpose registers
                      * six segment registers
                      * three pointer registers
                      * one flag register
                      * two index registers

All of them are 32 bit long except segment registers which are 16 bit long.

General Purpose Registers :-

  • The 4 general purpose registers are EAX, EBX, ECX, EDX
  • The 'E' stands for the Extended.
  • These registers are also used as 8 bit or 16 bit.
  • The EAX register is used as the Accumulator register (store result of operation)
  • The EBX register is used as base register also used in indexed addressing
  • The ECX register is used as counter register in instruction like loop
  • The EDX register is use in i/o operations also used to store big result along with EAX register in multiplication and division operation.
  • [ The ESP, EBP, ESI, EDI are also general purpose registers. ]
Why they are called as general purpose registers?

       Because they can be used for anything like you can use EAX register for counter register as well but under certain circumstances these register has to used for what they meant.(like for generally function calling).

Segment Registers:-

  • The six segment registers are CS, SS, DS, ES, FS and GS. 
  • The CS and SS are the code and the stack segment registers respectively, while DS, ES, FS, GS are 4 data segment registers.

Pointer Registers:-

  • The 3 pointer registers are ESP, EBP, EIP.
  • The ESP register is used as the Stack Pointer and is always points to the top of the stack.
  • The EBP register is used as the base pointer and is together with the ESP makes a stack frame.
  • The EIP register is used as the instruction pointer and stores the address of next instruction going to be executed by the CPU. 

Flag Register:-

  • The Flag registers (EFLAG) shows the status of instruction or operation which is executed by the CPU.
  • The Flag register is broad in terms of explanation so I am going to publish a new blog post for it which is in fact the next post.

Index Registers:-

  • The 2 index registers are ESI and EDI.
  • The ESI is used as source index for string operations.
  • The EDI is used as source destination for string operations.
This is just high level overview of these concepts and don't worry if you didn't understand anything as I will be covering these concepts in more detail in the reverse engineering section.

That's it for this post in the next post we are going to see the flag registers and how they work. till then keep smiling :)
Assembly Language (Intel x86) - Register Organization Assembly Language (Intel x86) - Register Organization Reviewed by h4kk4 on February 24, 2020 Rating: 5

No comments:

Enter your comments here if you need any help:

Powered by Blogger.