2 stack pointer (sp) – Texas Instruments MSP430x4xx User Manual

Page 39

Advertising
background image

CPU Registers

3-5

RISC 16-Bit CPU

3.2.2

Stack Pointer (SP)

The stack pointer (SP/R1) is used by the CPU to store the return addresses
of subroutine calls and interrupts. It uses a predecrement, postincrement
scheme. In addition, the SP can be used by software with all instructions and
addressing modes. Figure 3−3 shows the SP. The SP is initialized into RAM
by the user, and is aligned to even addresses.

Figure 3−4 shows stack usage.

Figure 3−3. Stack Pointer

0

15

0

Stack Pointer Bits 15 to 1

1

MOV

2(SP),R6

; Item I2 −> R6

MOV

R7,0(SP)

; Overwrite TOS with R7

PUSH

#0123h

; Put 0123h onto TOS

POP

R8

; R8 = 0123h

Figure 3−4. Stack Usage

I3

I1

I2

I3

0xxxh

0xxxh − 2

0xxxh − 4

0xxxh − 6

0xxxh − 8

I1

I2

SP

0123h

SP

I1

I2

I3

SP

PUSH #0123h

POP R8

Address

0123h

The special cases of using the SP as an argument to the PUSH and POP
instructions are described and shown in Figure 3−5.

Figure 3−5. PUSH SP - POP SP Sequence

SP

1

SP

old

SP

1

PUSH SP

The stack pointer is changed after
a PUSH SP instruction.

SP

1

SP

2

POP SP

The stack pointer is not changed after a POP SP
instruction. The POP SP instruction places SP1 into the
stack pointer SP (SP2=SP1)

Advertising