On Mon, 22 May 1995 12:58:23 +0100 (BST), Nigel J Kettlewell said:
> Surely JR is quicker, as it has to read less data in the first place?

> Once it's read the data, the actual execution might be quicker, but since JP
> has to read 3 bytes, and JR reads 2, then you're saving a whole memory
> cycle's worth of time!!! And a whole byte of memory, as well!!!

Well what can I say except...

WRONG!

On a sensible machine, a JP instruction does this.

 fetch+decode  4 cycles
 fetch         3 cycles
 fetch         3 cycles
              ---------
              10 cycles

The jump takes no time since (if the condition is true) the bytes are
loaded straight into the PC.

A JR does this.

 fetch+decode       4 cycles
 fetch              3 cycles
 if true then jump  5 cycles
                   ---------
                   12 cycles

The jump takes 5 cycles because the CPU has to add a signed 7-bit number to
an unsigned 16-bit number using an 8-bit ALU.  These 5 cycles are not used
if the condition turns out to be false (aside: guess why LDIR takes 5 more
cycles when BC>0 than it does when BC=0...).

Hence, on a sensible machine, JP is faster even though it takes one more
machine cycle.

On a Sam, both instructions take 12 because each fetch is restricted by the
ASIC to take place at a multiple of 4 clock cycles.

imc

Reply via email to