11
8008H–AVR–04/11
ATtiny48/88
As shown in
Figure 4-2, each register is also assigned a data memory address, mapping them
directly into the first 32 locations of the user Data Space. Although not being physically imple-
mented as SRAM locations, this memory organization provides great flexibility in access of the
registers, as the X-, Y- and Z-pointer registers can be set to index any register in the file.
4.5.1
The X-register, Y-register, and Z-register
The registers R26:R31 have some added functions to their general purpose usage. These regis-
ters are 16-bit address pointers for indirect addressing of the data space. The three indirect
address registers X, Y, and Z are defined as described in
Figure 4-3.
Figure 4-3.
The X-, Y-, and Z-registers
In the different addressing modes these address registers have functions as fixed displacement,
automatic increment, and automatic decrement (see the instruction set reference for details).
4.6
Stack Pointer
The stack is mainly used for storing temporary data, local variables and return addresses after
interrupts and subroutine calls. The Stack Pointer registers (SPH and SPL) always point to the
top of the stack. Note that the stack grows from higher memory locations to lower memory loca-
tions. This means that the PUSH instructions decreases and the POP instruction increases the
stack pointer value.
The stack pointer points to the area of data memory where subroutine and interrupt stacks are
located. This stack space must be defined by the program before any subroutine calls are exe-
cuted or interrupts are enabled.
The pointer is decremented by one when data is put on the stack with the PUSH instruction, and
incremented by one when data is fetched with the POP instruction. It is decremented by two
when the return address is put on the stack by a subroutine call or a jump to an interrupt service
routine, and incremented by two when data is fetched by a return from subroutine (the RET
instruction) or a return from interrupt service routine (the RETI instruction).
The AVR stack pointer is typically implemented as two 8-bit registers in the I/O register file. The
width of the stack pointer and the number of bits implemented is device dependent. In some
15
0
X-register
7
XH
07
XL
0
R27
R26
15
0
Y-register
7
YH
07
YL
0
R29
R28
15
0
Z-register
7
ZH
07
ZL
0
R31
R30