Registers

In the previous post, we explored the memory architecture of a computer system examining its various components and how access speed differs between them. Now, let’s take a deeper dive into registers, the fastest memory component in this hierarchy and the one closest to the CPU.

You can think of registers as a special kind of memory built right into the CPU that is very small, but extremely fast to access. There are many different kinds of registers in x86-64, and for now we'll only focus on the so-called general-purpose registers, of which there are sixteen. Each of them is 64 bits wide, and for each of them the lower byte, word and double-word can be addressed individually (incidentally, 1 "word" = 2 bytes, 1 "double-word" = 4 bytes, in case you haven't heard this terminology before).

Register
Lower byte
Lower word
Lower dword

rax

al

ax

eax

rbx

bl

bx

ebx

rcx

cl

cx

ecx

rdx

dl

dx

edx

rsp

spl

sp

esp

rsi

sil

si

esi

rdi

dil

di

edi

rbp

bpl

bp

ebp

r8

r8b

r8w

r8d

r9

r9b

r9w

r9d

r10

r10b

r10w

r10d

r11

r11b

r11w

r11d

r12

r12b

r12w

r12d

r13

r13b

r13w

r13d

r14

r14b

r14w

r14d

r15

r15b

r15w

r15d

Additionally, the higher 8 bits of rax, rbx, rcx and rdx can be referred to as ah, bh, ch and dh.

Some instructions can only be used with certain registers, and some registers have special meaning for certain instructions. In particular, rsp holds the stack pointer (which is used by instructions like push, pop, call and ret), and rsi and rdi serve as source and destination index for "string manipulation" instructions. Another example where certain registers get "special treatment" are the multiplication instructions, which require one of the multiplier values to be in the register rax, and write the result into the pair of registers rax and rdx.

In addition to these registers, we will also consider the special registers rip and rflags. rip holds the address of the next instruction to execute. It is modified by control flow instructions like call or jmp. rflags holds a bunch of binary flags indicating various aspects of the program's state, such as whether the result of the last arithmetic operation was less, equal or greater than zero. The behavior of many instructions depends on those flags, and many instructions update certain flags as part of their execution. The flags register can also be read and written "wholesale" using special instructions.

Last updated