Stack pointer, Atmega128(l) – Rainbow Electronics ATmega128L User Manual
Page 12

12
ATmega128(L)
2467B–09/01
Stack Pointer
The stack is mainly used for storing temporary data, for storing local variables and for
storing return addresses after interrupts and subroutine calls. The stack pointer register
always points to the top of the stack. Note that the stack is implemented as growing from
higher memory locations to lower memory locations. This implies that a stack PUSH
command decreases the stack pointer.
The Stack Pointer points to the data SRAM stack area where the Subroutine and Inter-
rupt Stacks are located. This Stack space in the data SRAM must be defined by the
program before any subroutine calls are executed or interrupts are enabled. The Stack
Pointer must be set to point above $60. The Stack Pointer is decremented by one when
data is pushed onto the Stack with the PUSH instruction, and it is decremented by two
when the return address is pushed onto the Stack with subroutine call or interrupt. The
Stack Pointer is incremented by one when data is popped from the Stack with the POP
instruction, and it is incremented by two when data is popped from the Stack with return
from subroutine RET or return from interrupt RETI.
The AVR Stack Pointer is implemented as two 8-bit registers in the I/O space. The num-
ber of bits actually used is implementation dependent. Note that the data space in some
implementations of the AVR architecture is so small that only SPL is needed. In this
case, the SPH register will not be present.
RAM Page Z Select Register –
RAMPZ
• Bits 7..2 - Res: Reserved Bits
These are reserved bits and will always read as zero. When writing to this address loca-
tion, write these bits to zero for compatibility with future devices.
• Bit 1 - RAMPZ0: Extended RAM Page Z-pointer
The RAMPZ register is normally used to select which 64K RAM Page is accessed by the
Z pointer. As the ATmega128 does not support more than 64K of SRAM memory, this
register is used only to select which page in the program memory is accessed when the
ELPM/SPM instruction is used. The different settings of the RAMPZ0 bit have the follow-
ing effects:
Note that LPM is not affected by the RAMPZ setting.
Bit
15
14
13
12
11
10
9
8
SP15
SP14
SP13
SP12
SP11
SP10
SP9
SP8
SPH
SP7
SP6
SP5
SP4
SP3
SP2
SP1
SP0
SPL
7
6
5
4
3
2
1
0
Read/Write
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Initial value
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
Bit
7
6
5
4
3
2
1
0
–
––
–
–
–
–
–
RAMPZ0
RAMPZ
Read/Write
R
R
R
R
R
R
R
R/W
Initial value
0
0
0
0
0
0
0
0
RAMPZ0 = 0:
Program memory address $0000- $7FFF (lower 64K bytes) is
accessed by ELPM/SPM
RAMPZ0 = 1:
Program memory address $8000- $FFFF (higher 64K bytes) is
accessed by ELPM/SPM