Memory address decrement and increment – Zilog Z16F2810 User Manual
Page 51

UM018809-0611
Operand Addressing
ZNEO
®
CPU Core
User Manual
35
If the required offset for a PC-based instruction exceeds the allowed range, the assembler
may silently convert the instruction to use the 32-bit immediate addressing mode.
Memory Address Decrement and Increment
In certain circumstances, a register-indirect LD operation can automatically decrement or
increment the base address register. A decrement is selected by adding a ‘--’ (double-
minus) prefix to the destination register name. The decrement always takes place before
the load is performed. This is called predecrement.
Example.
The following statement decrements the base address in register R5, then loads
the memory location pointed to by R5 with the 32-bit contents of R6:
LD (--R5), R6
Predecrement is supported only for destination operands. An LD store using predecrement
is similar to a PUSH, except the LD mnemonic allows a value in any register to be used as
the base address (See the
section on page 36 for more infor-
mation).
An increment is selected by adding a ‘++’ (double-plus) suffix to the source or destination
register name. The increment always takes place after the load is performed. This is called
postincrement.
Example.
The following statement loads the memory location pointed to by register R5
with the contents of R6, then increments the base address in R5:
LD (R5++), R6
Postincrement can also be used for source operands. For example, the following statement
loads register R6 with the contents of the memory location pointed to by R5, then incre-
ments the base address in R5:
LD R6, (R5++)
An LD read using postincrement is similar to a POP, except the LD mnemonic allows a
value in any register to be used as the base address. The predecrement and postincrement
features can be used to implement high-level stack data structures independent of the
Stack Pointer. To help ensure that the next base address is valid, the increment or decre-
ment amount varies with the size of the LD operation.
This is illustrated in the following example statements:
LD.B (--R5), R6 ; Decrement R5 by 1 and store 1 byte
LD.W (--R5), R6 ; Decrement R5 by 2 and store 2 bytes
LD (--R5), R6 ; Decrement R5 by 4 and store 4 bytes
Predecrement or postincrement operands cannot include an offset.
Note: