10 accessing data memory -41 – Maxim Integrated MAXQ7666 User Manual
Page 43

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
1.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 reg-
isters 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
The Frame Pointer (BP[OFFS]) is actually composed of a base pointer (BP) and an offset from the base pointer (OFFS). For the frame
pointer, the offset register (OFFS) is the target of any increment or decrement operation. The base pointer (BP) is unaffected by incre-
ment and decrement operations on the Frame Pointer. Similar to DP[n], the OFFS register may be pre-incremented/decremented when
writing to data memory and may be post-incremented/decremented when reading from data memory.
move A[0], @BP[OFFS--]
; decrement OFFS after read
move @BP[++OFFS], A[1]
; increment OFFS before write
All three data pointers support both byte and word access to data memory. Each data pointer has its own word/byte select (WBSn)
special-function register bit to control the access mode associated with the data pointer. These three register bits (WBS2, which con-
trols BP[OFFS] access; WBS1, which controls DP[1] access; and WBS0, which controls DP[0] access) reside in the Data Pointer
Control (DPC) register. When a given WBSn control bit is configured to 1, the associated pointer is operated in the word access mode.
When the WBSn bit is configured to 0, the pointer is operated in the byte access mode. Word access mode allows addressing of
64kWords of memory while byte access mode allows addressing of 64kBytes of memory.
MAXQ7665/MAXQ7666 User’s Guide
1-41
Maxim Integrated