beautypg.com

9 accessing the stack, 10 accessing data memory, 9 accessing the stack -15 – Maxim Integrated MAXQ Family User Manual

Page 40: 10 accessing data memory -15, Maxq family user’s guide

background image

3-15

3.9 Accessing the Stack

The hardware 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 increments 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 pre-

fix register. The @++SP stack access mnemonic is the associated destination specifier that generates this push behavior, thus the fol-

lowing 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 decrements 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 clears the INS bit to 0. Thus, the following two instructions

would be equivalent:

popi IP

reti

The @SP-- mnemonic can be used by the MAXQ microcontroller so that stack values may 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 stack

add @SP--

; with Acc, disregarding overflow

add @SP--

The stack pointer SP can be set explicitly, however only those least significant bits needed to represent the stack depth for the asso-

ciated MAXQ device are used. For a MAXQ device that has a stack depth of 16 words, only the lowest four bits are used and setting

SP to 0Fh will return it to its reset state.

Since the stack is 16 bits wide, it is possible to store two 8-bit register values on it in a single location. This allows more efficient use

of the stack if it is being used to save and restore registers at the start and end of a subroutine.

SubOne:

move PFX[0], IC

push PSF

; store IC:PSF on the stack

...

pop GR

; 16-bit register

move IC, GRH

; IC was stored as high byte

move PSF, GRL

; PSF was stored as low byte

ret

3.10 Accessing Data Memory

Data memory is accessed through the data pointer registers DP[0] and DP[1] or the Frame Pointer BP[Offs]. Once one of these regis-

ters is set to a location in data memory, that location can be read or written as follows, using the mnemonic @DP[0], @DP[1] or

@BP[OFFS] as a source or destination.

move DP[0], #0000h

; set pointer to location 0000h

move A[0], @DP[0]

; read from data memory

move @DP[0], #55h

; write to data memory

Either of the data pointers may be post-incremented or post-decremented following any read or may be pre-incremented or pre-decre-

mented before any write access by using the following syntax.

move A[0], @DP[0]++

; increment DP[0] after read

move @++DP[0], A[1]

; increment DP[0] before write

move A[5], @DP[1]--

; decrement DP[1] after read

move @--DP[1], #00h

; decrement DP[1] before write

MAXQ Family User’s Guide

Maxim Integrated