Skip to content
Go back

Short Note for Registers

Published:  at  09:40 PM

Table Of Contents

Open Table Of Contents

Intro

There are a lot of resources about registers so I assume you might already know them. This note is not a deep dive but a recap of how registers actually work.

Think of registers as super-fast little drawers inside the CPU. You use them to hold data temporarily while your program is running. They’re faster than RAM or disk. If you’re doing math or moving stuff around, the CPU wants it in a register.

Ready to take a peek into the registers on the x86_64 (Intel) architecture? :)

General Purpose Registers (64-bit)

NameWhat It’s Commonly Used For
raxReturn value from functions, math operations
rbxBase pointer (can be general-purpose too)
rcxLoop counter, string ops
rdxFunction arguments, I/O ops
rsiSource index for string/memory ops
rdiDestination index for string/memory ops
rspStack pointer (points to top of the stack)
rbpBase pointer (points to base of the stack)
r8 - r15Extra general-purpose registers (yay, 64-bit!)

You might not want to use rsp and rbp registers because of their functions. (They control how stack works). But you can perform arithmetic operations on them directly, which make them general purpose.

A Mini Example

section .text
    global _start

_start:
    mov rax, 5        ; Put 5 into rax
    mov rbx, 10       ; Put 10 into rbx
    add rax, rbx      ; rax = rax + rbx → 5 + 10 = 15

After running this, rax holds 15, just like a calculator using registers! Isn’t it awesome?

Other versions

rax, rbx, etc. are 64-bit. Want smaller versions? You can use:

Same goes for rbxebx, bx, bl, etc.

mov al, 0xFF        ; 8-bit
mov ax, 0xFFFF      ; 16-bit
mov eax, 0xDEADBEEF ; 32-bit

My dumb way of noting is, a single ‘F’ in ‘0xFF’ is 4 bit long.
So ‘F + F = 4 + 4 = 8 (0xFF is 8 bit)’.

Benefits!

What You’ll Learn from playing with registers:

Outro

Registers are your best friends when speaking assembly. They can give you the ability to control the CPU like a wizard with a wand. They’re fast, flexible, and essential.
Next time if you’re debugging or writing a shellcode, you’ll see these register names everywhere.
Happy Coding!


Spotted a Mistake?
Share this post on:

Previous Post
Caller vs Callee Saved Registers