Looking at the Z80 instruction set, we have indirect jumps JP (HL/IX/IY) but not indirect calls.
The "logical" way to do an indirect call probably is, looking at this, to do:
push returning address ld hl, function_pointer jp (hl) returning_address: ... code ...
But I saw another interesting and even better way through a tricky way, that is using the RET instruction.
push returning_address push function_pointer ret returning_address: ... code ...
It uses the RET behavior that pops to PC for the first indirect call. Then the function pointer will get the returning_address from the stack when returning.
See that by this way we have all the registers free for passing parameters, and also we can even do conditional call using the RET cc intruction.
Login or 등록 to post comments