How many x86 (32-bit) registers are there?
8: EAX, EBX, ECX, EDX, EDI, ESI, EBP, and ESP
EAX
Called the “accumulator register” because it’s the primary register used for common calculations, such as ADD and SUB). EAX has been given preferential status by assigning it more efficient, one-byte opcodes. EAX is also used to store the return value of a function. EAX refers to the 32-bit register in its entirety. AX refers to the least significant 16 bits, which can be broken further down into AH (the 8 most significant bits of AX) and AL (the 8 least significant bits).
What register components does EAX contain?
EAX (32-bits) contains AX (16-bits) which in-turn contains AH and AL, both 8-bits.
EBX
AKA The Base Register. In 32-bit architecture, EBX doesn’t really have a special purpose, so think of it as a catch-all for available storage. Can be referenced in whole (EBX) or in part (BX,BH,BL).
What parts can the EBX register be broken down to?
BX ( BH + BL )
ECX
The counter, or count, register is frequently used as a loop and function repetition counter, thought it can also be used to store any data. ECX can be broken down into parts (CX,CH,CL)
What can the ECX register be broken down to?
CX, CH, CL
EDX
The Data Register. Kind of like a partner to EAX. Often used in math operations like division and multiplication to deal with overflow where the most significant bits would be stored in EDX and the least significant in EAX. Also commonly used for storing function variables. Can be referenced in whole (EDX) or in part (DX,DH,DL)
What are the parts of the EDX register?
DX, DH, DL
ESI
The Source Index. The counterpart to EDI, ESI is often used to store the pointer to a read location. For example, if a function is designed to read a string, ESI would hold the pointer to the location of that string.
EDI
The Destination Index. Though it can be (and is) used for general data storage, EDI was primarily designed to store the storage pointers of functions, such as the write address of a string operation
EBP
The Base Pointer. EBP I used to keep track of the base/bottom of the stack. It is often used to reference variables located on the stack by using an offset to the current value of EBP, though if parameters are only referenced by the register, you may choose to use EBP for general use purposes.
ESP
The Stack Pointer. Used to track the top of the stack. As items are moved to and from the stack, ESP increments/decrements accordingly. Of all of the general purpose registers, ESP is rarely/never used for anything other than it’s intended purpose.
EIP
The Instruction Pointer. Not a general purpose register. EIP points to the memory address of the next instruction to be executed by the CPU. By controlling the EIP value, you can control the execution flow of an application.