Re: A85: DJNZ


[Prev][Next][Index][Thread]

Re: A85: DJNZ



On Mon, 28 Jul 1997 12:02:57 -0500 John Koch <john@imagin.net> writes:
>Question, how do I use DJNZ.  I'm trying to make a loop that plots
>pixels in rows and things.  Can someone please explain this to me.

This instruction is similar to the conditional jump instructions except
that a register value is used to determine branching.  The B register is
decremented and if a non zero value remains, program execution jumps to
the specified label.  If a zero value remains, the next instruction to be
executed is taken from the location following this instruction.


Example taken from Zilog books:
  A typical software routine is used to demonstrate the use of 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	B,80		;Set up counter
	LD	HL,Inbuf	;Set up pointers
	LD	DE,Outbuf

LOOP:	LD	A,(HL)		;Get next byte from
				;input buffer
	LD	(DE),A		;Store in output buffer
	CP	0DH		;Is it a CR?
	JR	DONE		;Yes finished
	INC	HL		;Increment pointers
	INC	DE
	DJNZ	LOOP		;Loop back if 80
				;bytes have not
				;been moved
DONE:


Sincerely,
The Unibomer

Jared Ivey
Unibomer@Juno.com
Ham Call Sign: KF4BXL
The Unibomer's Shack:
     http://www.geocities.com/SiliconValley/Vista/7342/
 _______________________
|  Florida Times Union  |
|=======================|
| Unibomer Strikes Again|
|   ~~~~~~~~~~~~~~~~~~~ |
| ~~~~~~~~~~~~~~~~~~~~~ |
| ~~~~~~~~~~~~~~~~~~~~~ |
| ~~~~~~~~~~~~~~~~~~~~~ |
| ~~~~~~~~~~~~~~~~~~~~• |
|_______________________|


References: