beautypg.com

Zilog Z08470 User Manual

Page 288

background image

Z80 Instruction Set

UM008007-0715

276

Z80 CPU
User Manual

Condition Bits Affected

None.

Example

A typical software routine is used to demonstrate the use of the DJNZ instruction. This
routine moves a line from an input buffer (INBUF) to an output buffer (OUTBUF). It
moves the bytes until it finds a CR, or until it has moved 80 bytes, whichever occurs first.

LD

8, 80

;Set up counter

LD

HL, Inbuf

;Set up pointers

LD

DE, Outbuf

LOOP: LID

A, (HL)

;Get next byte from

;input buffer

LD

(DE), A

;Store in output buffer

CP

ODH

;Is it a CR?

JR

Z, DONE

;Yes finished

INC

HL

;Increment pointers

INC

DE

DJNZ LOOP

;Loop back if 80

;bytes have not

;been moved

DONE:

This manual is related to the following products: