beautypg.com

Zilog Z8F0130 User Manual

Page 158

background image

eZ8

CPU Core

User Manual

UM012820-0810

DJNZ Instruction

143

Sample Usage

DJNZ typically controls a loop of instructions. In this example, 18 bytes
are moved from one buffer area in the Register File to another and the
steps involved are:

1. Load the R6 counter with 18d (

12h

).

2. Load the R4 source pointer.

3. Load the R2 destination pointer.

4. Set up the loop to perform moves.

5. End loop with DJNZ.

The assembly listing required for this routine is as follows:

Ld R6, #12h

;Load counter with 12h (18d)

Ld R4, #36h

;Load source pointer

Ld R2, #24h

;Load destination pointer

LOOP: Ld R3, @R4

;Load byte in R3 from source

Ld @R2, R3

;Write byte to destination

dec R4

;Decrement source pointer

dec R2

;Decrement destination pointer

djnz R6, loop ;Decrement and loop until count =

0