2009
12.19

General purpose CPU register

I just needed to type this somewhere so I don’t forget. Maybe by putting it here, it will be of some use to others.

A CPU uses 8 general purpose registers: EAX, EDX, ECX, ESI, EDI, EBP, ESP and EBX.
Each register is design for a particular purpose, and each performs a function that enables the CPU to efficiently process information.

The EAX register, is used to perform calculations as well as storing return values from function calls. Basic operations ilke add, subtract, and compare are optimized to use the EAX register. More specialized operations like multiplication and dvision can occur only within the EAX register.

The EDX is the data register. It’s basically an extension of EAX to assist it in storing extra data for complex operations. It can also be used for general purpose data storage.

The ECX, also called the count register, is used for looping operations. The repeated operations could be storing a string or counting numbers.

The ESI and EDI relied upon by loops that process data. The ESI register is the source index for data operation and holds the location of the input data stream. The EDI points to the location where the result of data operation is stored, or the destination index.

ESP is the stack pointer, and EBP is the base pointer. These registers are used for managing function calls and stack operations. When a function is called, the function’s arguments are pushed on the stack and are followed by a return address. The ESP register points to the very top of the stack, so it will point to the return address. EBP is used to point to the bottom of the call stack.

EBX is the only register that was not designed for anything specific. It can be used for extra storage.

EIP is the register that points to the current instruction being executed. As the CPU moves through the binary executing code, EIP is updated to reflect the location where the execution is occuring.