ATMega registers and memory ranges
The AVR family has a reasonably complex register and memory architecture, with:
- Multiple address spaces
- Registers that can be accessed directly and via the memory address space
- Register pairs that are used as memory indexes
- Restrictions on which registers can be loaded directly with constant values
- Some IO ports that appear in both the memory and IO address spaces, but with different addresses in each
- Some IO ports that are only accessible via the memory address space
In addition, the gcc compiler has conventions governing which registers it uses for what purpose, for example:
- Which registers it uses for purposes such as storing temporary values and zero
- Which registers it uses for passing and returning arguments
- Which registers it uses as a stack frame pointer
- Which registers are saved by the caller on entry to a subroutine and which ones have to be saved by the callee
When I'm reading the assembler output of gcc I find it helpful to have a table to remind me which registers are being used for what, and why. The information is not exactly well-explained in the AVR documentation and I've not been able to find all the information in once place on the Internet, so I've drawn up the following quick-reference table to remind me of what goes where:
Click on the image for a PDF copy of the table. I hope you find this useful, corrections and suggestions welcome - please leave a comment below!
References