Noob question, trying to pass variables in subroutines.

Página 2/2
1 |

Por ARTRAG

Enlighted (6923)

Imagen del ARTRAG

12-01-2011, 20:54

For normal z80 systems:
JR ss,e takes 12 cycles if ss is true and 7 cycles if ss is false
JP cc,nn takes 10 cyles always
(note that on MSX there are extra wait cycles)

Por commodorejohn

Expert (92)

Imagen del commodorejohn

12-01-2011, 21:56

JP is only faster if the jump is taken (condition is true). If not, then JR is faster.
Oh, right. My mistake.

like?:

jump:	ld a,0
	bit 0,a
	jp z,jump  ;faster because condition is true
	jr nz,jump ;jump has not been taken yet using jp nz,jump would be slower


Not sure if this is a serious example or not, but there's no point in using both JP and JR together - you're stacking two instructions to create something that's slower than either. JP would be better for branches that are more likely to be taken than not, whereas JR would be better for branches that are less likely to be taken - you'll want to pick whichever's best-suited for any given instance.

Por Daemos

Paragon (2044)

Imagen del Daemos

12-01-2011, 22:07

That example is just to clear up which one of both would be faster. I would certainly not use it in any program that way Wink

How important is it to watch these jp/jr codes? How bad will the slowdown or speedup be?

Por Edwin

Paragon (1182)

Imagen del Edwin

12-01-2011, 22:12

It's not really that important. If speed is not an issue, you would use jr where you can because it saves you a byte. But once you start making timing critical code are or in desperate need of optimisation, you'd start looking at speed this closely. You're talking about a margin of 5 cycles. Or 0.0000014 seconds Tongue

Página 2/2
1 |