Register Allocation Table - RAT

When targeting the ATMega328P we have 32 general-purpose Registers, some of which have special restrictions on which instructions they can be used with.

For this Reason we maintain a Register Allocation Table, so during Assembly Code Generation, we can make a good choice on which Register to use for a temporary value.

Properties as an Allocator

As an Allocator, the RAT manages 32 Registers. Registers can be allocated / freed in any order. When allocating a Register, it is important to know what it will be used for. Because we only manage 32 Registers, we can keep a lot of metadata, as opposed to e.g. Memory Allocators.

Managing the Stack Pointer - SP

The Stack Pointer needs to be setup before the start of the Program. That's why i consider it part of the RAT, because it needs to be managed. And maybe it could be setup in a different place. Typical AVR Program:

ldi    r16, LOW(RAMEND)
out    spl, r16
ldi    r16, HIGH(RAMEND)
out    sph, r16
image displaying the structure of the Register Allocation Table