© 2004 Microchip Technology Inc. DS70050C-page 3-9
Section 3. Data Memory
Data Memory
3
3.3.1.3 Modulo Address Calculation
The end address for an incrementing modulo buffer must be calculated from the chosen start
address and the chosen buffer length in bytes. Equation 3-1 may be used to calculate the end
address.
Equation 3-1: Modulo End Address for Incrementing Buffer
The start address for a decrementing modulo buffer is calculated from the chosen end address
and the buffer length, as shown in Equation 3-2.
Equation 3-2: Modulo Start Address for Decrementing Buffer
3.3.1.4 Data Dependencies Associated with Modulo Addressing SFRs
A write operation to the Modulo Addressing Control register, MODCON, should not be
immediately followed by an indirect read operation using any W register. The code segment
shown in Example 3-1 will thus lead to unexpected results.
Example 3-1: Incorrect MODCON Initialization
To work around this problem of initialization, use any Addressing mode other than indirect reads
in the instruction that immediately follows the initialization of MODCON. A simple work around to
the problem is achieved by adding a NOP after initializing MODCON, as shown in Example 3-2.
Example 3-2: Correct MODCON Initialization
End Address = Start Address + Buffer Length – 1
Start Address = End Address – Buffer Length + 1
Note 1: Using a POP instruction to pop the contents of the top-of-stack (TOS) location into
MODCON, also constitutes a write to MODCON. The instruction immediately
following a write to MODCON cannot be any instruction performing an indirect read
operation.
2: The user should note that some instructions perform an indirect read operation,
implicitly. These are: POP, RETURN, RETFIE, RETLW and ULNK.
MOV #0x8FF4, w0 ;Initialize MODCON
MOV w0, MODCON
MOV [w1], w2 ;Incorrect EA generated here
MOV #0x8FF4, w0 ;Initialize MODCON
MOV w0, MODCON
NOP ;See Note below
MOV [w1], w2 ;Correct EA generated here