please dont rip this site

Z80 Assembly - Instructions: Branching

Jump instructions

These are the instructions that change the place of execution without saving their own address for a possible return.

JP and JR

Syntax: jp/jr label or (hl)/(ix)/(iy) (unconditional) or jp/jr condition,label (conditional)

When arriving at any of these intructions, execution is immediately continued from the location denoted by the label given (you can use numbers instead of labels of course). If the operand is a register reference (e. g. jp (hl)), it means that the value of the register will be loaded into PC directly; these jumps can be unconditional only. Otherwise, if the condition is not fulfilled, execution continues as if there wasn't any jump. The flags are preserved in all the cases. The conditions can be the following:

conditionmeaning
ccarry (C) is set
nccarry is not set
zzero (Z) is set
nzzero is not set
msign (S) is set
psign is not set
peparity/overflow (P/V) is set
poparity/overflow is not set

The most important difference between the two jumps is that jr calculates the jump address with respect to itself, and the destination must be in its 128-byte vicinity. Moreover, jr can only take the first four conditions of those listed above. Besides all these differences, jr is slower but also smaller than the corresponding jp, therefore you have to decide whether speed or size is more important in the piece of code you place the jump into.

DJNZ

Syntax: djnz label

B is decreased, and a jr label happens if the result was not zero. The flags are preserved. Since this is a relative jump, it can only point to its 128-byte vicinity.

Subroutine instructions

The two instructions of this section are also jumps, but by taking advantage of the stack, they offer the possibility to create subroutines.

CALL

Syntax: call label (unconditional) or call condition,label (conditional)

The address of the instruction immediately following the call (i. e. PC+3) is saved to the stack, and execution is continued from the address given by the label. The conditions are the same as those of the absolute jump, i. e. all the eight conditions can be used. The flags are preserved.

RET

Syntax: ret (unconditional) or ret condition (conditional)

The word on the top of the stack is retrieved and it is used as the address of the next instruction from which the execution is to be continued. This is basically a pop pc. The conditions work the same way as above, all of them can be used. The flags are preserved.

Back to the index


file: /Techref/zilog/z80/app1c.htm, 3KB, , updated: 2018/11/6 16:43, local time: 2024/11/24 11:40,
TOP NEW HELP FIND: 
3.144.90.236:LOG IN

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://ecomorder.com/techref/zilog/z80/app1c.htm"> Z80 Assembly</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

 

Welcome to ecomorder.com!

 

Welcome to ecomorder.com!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .