View Full Version : Call/return mechanism

02-05-2007, 05:51 AM
I understand that the cog's do not have a return stack mechanism.

But do I understand correctly that a Call instruction not only does a jump to the subroutine, but also, at run time, modifies the correct return instruction so that return instruction will jump back to the right place (directly after the originating call)?
I't the only thing that makes sense, and the manual is a bit scarce on the actual details.


Mike Green
02-05-2007, 05:55 AM
Yes, the JMPRET instruction stores the address of the next instruction into the source field of the destination, then jumps to the address in the source field of the JMPRET. The CALL instruction is a kind of macro that produces a JMPRET by taking the label of the jump address and adding a "_ret" to it and checking that the actual resulting line contains a RET instruction (which itself is really a JMP instruction).