What do you mean? Im still fairly un-familiar with call and return. Arent they just for running subroutines? Why not just have a branch to the sub routine?
(03-11-2015, 07:41 PM)greatgamer34 Wrote: ...call and return. Arent they just for running subroutines? Why not just have a branch to the sub routine?
You're right they "just" run subroutines.... but it saves the programmer work, and saves memory (program space). "Call" is like "branch", but it automagically stores a return address, which means the end of the subroutine is simply a "return" instead of a "jump to <address>".
Sure, I could (among other possibilities)
Code:
PUSH <PC + 4>
JMP <subroutine>
and my subroutine could finish with
Code:
PULL reg0
JMP <reg0>
But you're looking at probably 4-bytes of instruction per call, and another 4-bytes for return. (That's assuming you've got PUSH and PULL instructions). Instead with call and return, you're looking at probably 2-bytes per CALL and 1-byte to return.
It might not sound like much, but how much program memory does the average Redstone computer have?
And then there's the debugging cost: with automagic CALL and RETURN, there's no way for me to screw up and push the wrong return address, or forget to push anything at all.
RISC-16 (that's the ISA ur using right? Link is broken) can emulate calls quite adequately with the JALR (jump and link register) instruction. Just jump to an address and save the PC to memory / software stack. Just an extra instruction, unless of course you're implementing software stack then maybe an extra 2.
You're right: it can be done. But with IS-level-support for subroutines, the correct pointer is automatically stored and retrieved. Shorter programs, less bugs. (or, to look at it another way... more work for the hardware engineer, less for the software developer)