This set of tutorial notes has been created on a Raspberry Pi running Debian.
As it is a linux based operating system there are built in C libraries that will be used to make programming easier.
Specifically, the built in funtions "printf" and "scanf" will be used to handle user input and output.
All the assembly will be done using the gcc assembler using the -g flag.
The ARM64 architecture has 30 registers available for general use. This does not include the floating point registers which will be discussed later.
The primary purpose of each register is shown in the table below.
| Register | Purpose | Register | Purpose | Register | Purpose |
|---|---|---|---|---|---|
| X0 | Argument and Return | X11 | Temporary / scratch | X21 | General purpose, callee-saved |
| X1 | Argument and Return | X12 | Temporary / scratch | X22 | General purpose, callee-saved |
| X2 | Argument and Return | X13 | Temporary / scratch | X23 | General purpose, callee-saved |
| X3 | Argument and Return | X14 | Temporary / scratch | X24 | General purpose, callee-saved |
| X4 | Argument and Return | X15 | Temporary / scratch | X25 | General purpose, callee-saved |
| X5 | Argument and Return | X16 | IP0, Intra-procedure-call / scratch | X26 | General purpose, callee-saved |
| X6 | Argument and Return | X17 | IP0, Intra-procedure-call / scratch | X27 | General purpose, callee-saved |
| X7 | Argument and Return | X18 | Platform register | X28 | General purpose, callee-saved |
| X8 | Temporary / scratch | X19 | General purpose, callee-saved | X29 | Frame pointer |
| X9 | Temporary / scratch | X20 | General purpose, callee-saved | X30 | Link register |
| X10 | Temporary / scratch |
Green registers are safe and will not be altered by any function calls. Data stored in these registers can be relied on to remain unless explicitly changed by the code.
Orange registers can be freely used but any call using a branch-and-link (e.g. bl printf, bl scanf) will overwrite these registers so when the code recommences after the call these registers will probably contain different values to those before the call.
Red registers are needed by the operating system and should not be used. If they are to be used by code, their contents need to be saved, by pushing to the stack or storing on the heap, before being used, then restored to their original values.
Best to avoid these registers altogether.