Noob question, trying to pass variables in subroutines.

페이지 2/2
1 |

By ARTRAG

Enlighted (6923)

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)

By commodorejohn

Expert (92)

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.

By Daemos

Paragon (2044)

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?

By Edwin

Paragon (1182)

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

페이지 2/2
1 |