August 5, 2023

Assembly language - ARM registers

If you are new to assembly language, the first thing to know is that it is all about registers. You move stuff in and out of registers and operate on stuff in registers. The more the better. Plain old 32 bit ARM (which is what we are talking about) has 16 registers 32 bit in size. Just for the record, 64 bit ARM has 32 registers, 64 bits in size -- something to tantalize you for some future day.

The registers are called r0 through r15 -- none of the crazy A, B, C or AX, BX, rubbish from ancient crusty processors. In general, all of the registers act the same, with some exceptions that we will talk about right now.

r15 is the PC (program counter). Writing to it will cause a program jump. This is rarely (almost never) done. If you follow the rule of "don't mess with it" you will do fine.

r14 is the LR (link register). This is used for calling subroutines. It is all you need if you only ever call one level deep, otherwise you will need to save and restore it to and from the stack.

r13 is the SP (stack pointer).

That is the whole story if you are an assembly language programmer. If you need to interface to the C compiler (or understand assembly generated by the C compiler) you also need to know about r11.
r11 is the FP (frame pointer). Explaining how the compiler uses it is beyond what we intend to tackle here.

It is odd that r12 is skipped over. The Gnu C compiler (gcc) refers to it as "ip", but uses it as a general register. As near as I can tell, r12 is freely available for general use. Someone at some time must have had some idea about using it for something special, but that is lost in the mists of time.

So, as an assembly programmer you have 13 registers, 32 bits in size that you can use as you see fit. A world of luxury if you come from older processors.


Feedback? Questions? Drop me a line!

Tom's Computer Info / tom@mmto.org