beautypg.com

7 conditional return from interrupt, 8 accessing the stack, 3 .7 .7 conditional return from interrupt -15 – Maxim Integrated MAXQ622 User Manual

Page 51: 3 .8 accessing the stack -15

background image

MAXQ612/MAXQ622 User’s Guide

Maxim Integrated

3-15

3.7.7 Conditional Return from Interrupt

Similar to the conditional returns, the MAXQ612/MAXQ622 microcontrollers also support a set of conditional return
from interrupt operation . Based upon the value of one of the status flags, the CPU can conditionally pop the stack, set
the IPS bits to 11b, and begin execution at the address popped from the stack . If the condition is not true, the condi-
tional return from interrupt instruction leaves the IPS bits unchanged, does not pop the stack and does not change the
instruction pointer . The following conditional return from interrupt operations are supported:

RETI C

; if C=1, a RETI is executed

RETI NC

; if C=0, a RETI is executed

RETI Z

; if Z=1 (Acc=00h), a RETI is executed

RETI NZ

; if Z=0 (Acc<>00h), a RETI is executed

RETI S

; if S=1, a RETI is executed

3.8 Accessing the Stack

The soft stack is used automatically by the CALL, RET, and RETI instructions, but it can also be used explicitly to store
and retrieve data . All values stored on the stack are 16 bits wide .
The PUSH instruction increases the stack depth (by decrementing the stack pointer SP) and then stores a value on the
stack . When pushing a 16-bit value onto the stack, the entire value is stored . However, when pushing an 8-bit value
onto the stack, the high byte stored on the stack comes from the prefix register . The @++SP stack access mnemonic
is the associated destination specifier that generates this push behavior, thus the following two instruction sequences
are equivalent:

move PFX[0], IC
push PSF

; stored on stack: IC:PSF

move PFX[0], IC
move @++SP, PSF

; stored on stack: IC:PSF

The POP instruction removes a value from the stack and then decreases the stack depth (by incrementing the stack
pointer) . The @SP-- stack access mnemonic is the associated source specifier that generates this behavior, thus, the
following two instructions are equivalent:

pop PSF
move PSF, @SP--

The POPI instruction is equivalent to the POP instruction, but additionally sets the IPS bits to 11b’ . Thus, the following
two instructions would be equivalent:

popi IP
reti

The @SP-- mnemonic can be used by the MAXQ612/MAXQ622 so that stack values can be used directly by ALU
operations (e .g ., ADD src, XOR src, etc .) without requiring that the value be first popped into an intermediate register
or accumulator .

add @SP--

; sum the last three words pushed onto the

add @SP--

; with Acc, disregarding overflow

add @SP--

The stack pointer SP can be set explicitly, however, only the least significant bits needed to represent the stack depth
are used . The MAXQ612/MAXQ622 have a stack depth constrained only by the size of the SRAM, and the lowest 10
bits of SP are used . Setting SP to 03F0h returns it to its reset state .
On the MAXQ612/MAXQ622, the stack naturally grows downward from the top of the SRAM . A push operation
(move @++SP, …) increases the depth of the stack, but decreases the numeric value in the stack pointer . A pop
(move …, @SP--) decreases the depth of the stack, but decreases the numeric value in the stack pointer .

This manual is related to the following products: