NASM Coding: Volatile Registers

Throughout the execution of a NASM program, the contents of some registers will be 'wiped out' by the operating system.

Specifically, when we use the instruction

syscall
, the contents of the following registers will be erased (or replaced by 'garbage' values:)
rcx
and
r11
.

This means that we should avoid keeping values in a long-term fashion in these two registers.

Moreover, since the registers

rax
,
rdi
,
rsi
,
rdx
,
r10
,
r8
, and
r9
are used by us to store arguments to syscalls, we shouldn't keep important values in these registers in a long-term fashion, either.

In which registers can we keep values long-term?

Answer: the registers

rbx
,
r12
,
r13
,
r14
, and
r15
are guaranteed to never be modified by the operating system, so if we wish to store values for long duration throughout the execution of our NASM program, these $5$ registers are the right place.