Introduction to ARM64 assembly programming

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.

Registers

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
X0Argument and ReturnX11Temporary / scratchX21General purpose, callee-saved
X1Argument and ReturnX12Temporary / scratchX22General purpose, callee-saved
X2Argument and ReturnX13Temporary / scratchX23General purpose, callee-saved
X3Argument and ReturnX14Temporary / scratchX24General purpose, callee-saved
X4Argument and ReturnX15Temporary / scratchX25General purpose, callee-saved
X5Argument and ReturnX16IP0, Intra-procedure-call / scratchX26General purpose, callee-saved
X6Argument and ReturnX17IP0, Intra-procedure-call / scratchX27General purpose, callee-saved
X7Argument and ReturnX18Platform registerX28General purpose, callee-saved
X8Temporary / scratchX19General purpose, callee-savedX29Frame pointer
X9Temporary / scratchX20General purpose, callee-savedX30Link register
X10Temporary / 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.



| next → Hello World