AArch64/ARM64 Tutorial

Chapter 4: Basic Registers

Other than memory, there's one more place a CPU will keep data at. This place is known as the Registers. The Registers are important because the data here is what is used for the calculation of many Instructions.

In a modern CPU, there are 1000's of Registers. However, most of these we don't need to worry about. Registers can be categorized into 3 main groups..

Before we continue this thread further, I need to go off-topic and state that this tutorial will focus a little bit on the ARM Cortex-A57 CPU for its examples and applications. The Cortex A-57 obviously uses the ARMv8 AArch64 Assembly Language. This is the same CPU that is used in the Nintendo Switch (4-cores). There is tons of information, documentation, and debugging tools for this specific CPU.

Going back to the Registers, we will focus on the General Purpose Registers. There are 31 GPRs. Register #0 thru Register #30, or also known as r0 thru r30. Each GPR is 64-bits in length. Therefore a double-word value is the maximum size data type that can fit into a GPR.

All of the GPRs can be modified (read and/or write) by the CPU. Sometimes a GPR will contain a Memory Address (to use as a reference for a task), or it can contain a basic value (to represent something such as item count). Values in Registers are usally displayed in Hex form by an integer. No fractional integer numbers are able to exist within a GPR. Fractional numbers have to be in Floating Point form and are used in the FPRs.

Two of the GPRs have alternate names. r29 is known as the Frame Pointer (FP). r30 is known as the Link Register (LR). Frame Pointer is too complicated for a beginner to discuss as of now. The Link Register is a register that is used as a method for the CPU to execute sub-routines within a program. It will usually contain a Memory Address of some sorts.

There is a unique register (that is to be used as a GPR when needed) known as the Zero Register. You cannot write to it. It always contains the value of zero. We will discuss this register more in Chapter 6.

There are 2 more Registers I want to discuss very quickly before moving on. Those are the Program Counter (PC) and the Stack Pointer (SP). The PC is a read-only register. It simply keeps track of where the CPU is currently executing at within the program (Memory Address). The SP is used in conjunction with LR for subroutine use. SP will always contain a Memory Address.


Next Chapter

Tutorial Index