(no title)
gp2000 | 5 years ago
PMESS LD A,(HL) ; get character from message
INC HL ; move message pointer to next character
CP 10 ; newline?
RET Z ; return if so
OR A ; zero?
RET Z ; done if so
CALL PCHAR ; print character
JP PMESS ; keep looping
If instead of "RET Z" we had to do a conditional jump to a return it would be 10 cycles for each test instead of 5. CP 10
JP Z,DONE ; 10 cycles, jump taken or not
...
JP PMESS
DONE: RET ; 10 cycles, BTW
The conditional return just happens to be cheaper if not taken because it skips the work of popping the return address off the stack. Though purely an outcome of the implementation you can treat it as sort of a branch prediction.Incidentally, the Z-80 also has relative branches (JR) that differ in execution time whether they are taken or not. The branch offset is a single byte so JR is only 2 bytes compared to JP's 3. A JR is 7 cycles if not taken, 12 otherwise. Again, we can treat it as a hard-coded branch prediction that predicts the branch is not taken. If space or distance to target is not a problem, a JR is faster if taken less than 60% of the time.
No comments yet.