Using registers
Main memory access is slow. Performance is heavily impacted by how registers are used. Optimal register allocation is nondeterministic polynomial-time complete (NP-complete) – very difficult. Optimizing compilers expend great effort on register allocation to make the generated code very efficient; the generated code might or might not be optimal. That is beyond the scope of this book.
x64 has 16 general-purpose registers, illustrated in the following table. Many registers have a special role. Arithmetic is performed on an accumulator register, rax
. Several of the x64 registers have multiple names for accessing from 8 bits to all 64 bits of the register. This appears mainly to be for backward compatibility with legacy x86 code. In any case, Jzero only uses the 64-bit versions of registers, plus whichever 8-bit registers are necessary for strings. In AT&T syntax, register names are preceded by a percentage sign, as in %rax
:
Table 14.3: x64 registers...