Files
c_reverse/week1/day1/README.md
2026-05-30 10:31:26 +02:00

32 lines
1.2 KiB
Markdown

# Day 1: Variables, Memory, and the Stack
## 📝 Concepts Covered
Today we explored how high-level C variables are translated into low-level machine instructions and memory operations.
### 1. The Stack and RBP
Local variables in C are stored on the **Stack**. The CPU uses the `RBP` (Base Pointer) register as a reference point to find these variables.
- `int a = 123;` -> `mov DWORD PTR [rbp-4], 0x7b`
### 2. Register Basics (x64)
Registers are small, fast storage locations inside the CPU.
- `RAX`, `RBX`, `RCX`, `RDX`: General purpose 64-bit registers.
- `EAX`, `EBX`, `ECX`, `EDX`: The lower 32-bit halves of the above (used for `int` in C).
### 3. Data Sizes
The assembly instruction specifies how much data to move:
- `BYTE PTR`: 1 byte (`char`)
- `WORD PTR`: 2 bytes (`short`)
- `DWORD PTR`: 4 bytes (`int`)
- `QWORD PTR`: 8 bytes (`long` or pointers)
### 4. Arithmetic Pattern
CPUs perform arithmetic using a **Load-Modify-Store** cycle:
1. **Load** memory value into a register.
2. **Add/Sub** the register value.
3. **Store** the register result back into memory.
## 🛠 Exercises Completed
- `exo_1.c`: Basic assignment and hex identification.
- `exo_2.c`: Arithmetic deconstruction (The `add` instruction).
- `exo_3.c`: Data type sizes and memory offsets.