Understanding the x86-64 Architecture
Explore the foundational aspects of x86-64 architecture in this introductory article. Learn about its registers, memory model, instruction set, and the key differences from x86. Gain a solid understanding of how the CPU processes instructions, setting the stage for writing efficient assembly code.
Table of Contents
- Understanding the x86-64 Architecture
- Basic Overview
- Data Storage Sizes
- Center Processing Unit
- CPU Registers
- General Purpose Register
- Special Purposes of GPRs
- Stack Pointer Register (ESP)
- Base Pointer Register (RBP)
- Instruction Pointer Register (RIP)
- Flag Register (RFLAGS)
- XMM Registers
- Cache Memory
- Main Memory and Layout
- Memory Layout
- Conclusion
Basic Overview
All the Modern Computer uses Von-Neuman Architecture
Components :
- CPU
- Primary Storage : Volatile (Data erased when system got turned off)
- Secondary Storage : non-volatile (Data remains stored even after power-off)
- I/O Devices
Programs are stored in Secondary Memory -> Moved to Primary Memory when executing -> Executed by CPU
Data Storage Sizes
Following is the list of storage elements in x86-64:
Storage | Size(bits) | size(bytes) |
---|---|---|
Byte | 8-bit | 1 byte |
Word | 16-bits | 2 byte |
Double-World | 32-bits | 4 byte |
Quadword | 64-bits | 8 byte |
Double quadword | 128-bits | 16 byte |
For C/C++ People. Mapping of data type
Center Processing Unit
CPU is the brain of the computer as it performs all the operations and calculations.
Arithmetic Logical Unit is the performs the arithmetic and logical calculations.
- Registers and Cache Memory supports ALU.
CPU Registers
CPU registers are storage built into the CPU itself.
General Purpose Register
Following are the sixteen general purpose register :
Anatomy of a 64-Bit Register :
%ah
and%al
are 8 bits register.%ax
is of 16 bit which combines two 8 bit registers%ah
and%al
.%eax
is of 32 bit which combines a 16 bit%ax
register and additional 16 bits.%rax
is of 64 bit which combines a 32 bit registers%eax
and extra 32 bits.
Special Purposes of GPRs
There are some general purpose registers which has some special functions.
Stack Pointer Register (ESP)
- It points at the top of the stack.
NOTE : I will explain stack in details in later articles.
Base Pointer Register (RBP)
Base pointer register is also used in stack which stores the address of the base of the stack. RBP is mainly used by the function (Which actually uses the stack).
NOTE : I will explain functions and stack uses in details in later articles.
Instruction Pointer Register (RIP)
It stores the address of the memory location where the next instruction is stored.
Flag Register (rFlags)
It is used by the CPU to store status and control information. After each operation or instruction bits of rFlags register is updated by the CPU.
- Bits of rFlags register flag specific statuses.
XMM Registers
SIMD : Single instruction Multiple Data instructions allows single instruction to be applied simultaneously on multiple data.
XMM Registers are used by SIMD as XMM are 128 bits or 256 bit long they can stored multiple data in a single register which can be used by the SIMD Instructions.
Range : xmm0 to xmm16
Cache memory
Cache memory is the subset of main memory which is small in size, closer to the CPU which makes it faster when accessing data.
when a program request a data from memory the address of the memory location is stored in the address bus then the data is fetched from that memory location and stored in data bus which takes it to the CPU but what actually cache does is it stored the copy of the same data in it so CPU don’t have to uses buses to fetch the data.
Main memory and Layout
Memory is the series of byte where each byte or location has an address.
Memory uses little-endian architecture means the most significant byte is stored in highest memory address and least significant byte is stored in lowest memory address.
Example : 50 in decimal is 32 in hex
so in memory :
3 | address 1001 |
---|---|
2 | address 1000 |
Memory Layout
The general memory layout is as shown :
- Reserved section of the memory is not accessible by the program.
- text section is where our actual program instructions are stored.
- Initialized variables are stored in data section.
- BSS section contains the variable which are not initialized.
- head section contains the dynamically allocated data.
- stack is used by the functions to store parameters data and also used for preserving the registers during program execution.
Conclusion
Congratulations on completing your first step toward mastering x86-64 assembly! A solid understanding of the architecture is essential for writing efficient and effective code. Thank you for reading and embarking on this journey.