Kris3c's Space

Home About Article Hackries Writeups Projects KriTune

Understanding the x86-64 Architecture

image

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

  1. Understanding the x86-64 Architecture
  2. Basic Overview
  3. Data Storage Sizes
  4. Center Processing Unit
  5. CPU Registers
  6. General Purpose Register
  7. Special Purposes of GPRs
  8. Stack Pointer Register (ESP)
  9. Base Pointer Register (RBP)
  10. Instruction Pointer Register (RIP)
  11. Flag Register (RFLAGS)
  12. XMM Registers
  13. Cache Memory
  14. Main Memory and Layout
  15. Memory Layout
  16. Conclusion

Basic Overview

All the Modern Computer uses Von-Neuman Architecture

Components :

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

Screenshot From 2024-12-31 15-10-23

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.

CPU Registers

CPU registers are storage built into the CPU itself.

General Purpose Register

Following are the sixteen general purpose register :

Screenshot From 2025-01-01 00-29-16

Anatomy of a 64-Bit Register :

Screenshot From 2025-01-01 00-31-08

Special Purposes of GPRs

There are some general purpose registers which has some special functions.

Stack Pointer Register (ESP)

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.

Screenshot From 2025-01-01 00-49-51

Screenshot From 2025-01-01 00-50-11

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.

Screenshot From 2025-01-01 00-56-39

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 :

Screenshot From 2025-01-01 01-07-07

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.