excelCPU icon indicating copy to clipboard operation
excelCPU copied to clipboard

Add Jump With Return instruction

Open zHoeshin opened this issue 1 year ago • 3 comments

Basically adding support for calling functions. Jump with return pushes the PC to the stack(whether accessible elsewhere or not) and jumps. Return pops the value from the stack and jumps to this value.

zHoeshin avatar Jan 28 '24 12:01 zHoeshin

I hope I'm not mistaken, but I didn't see any hardware stack support in this ISA. You could use one of the GPRs to simulate a stack, however. But now we're talking ABI spec.

Without a TRAN PC, REG/TRAN REG, PC or JMP REG instruction, I can't see a trivial workaround to this issue.

I suppose you could theoretically implement a RET instruction as a JMP IMM, but before executing that instruction, modify the destination. You'd have a somewhat weird looking epilogue, because self-modifying code sucks, but it should work.

Macpunk avatar Jan 28 '24 21:01 Macpunk

Before thinking about a hardware support for the stack, I would implement a TRAN PC / REG and TRAN REG / PC. This would allow a software stack, with little changes to the current architecture. I think the multiplexer on the PC would need updating and accordingly there would be an instruction that could read from PC.

sergiodavies avatar Jan 28 '24 22:01 sergiodavies

I think jump with call not good for excel cpu. excel cpu is already slow, should optimize running code by inlining function instead of having redundant call ret. like shader for gpu do.

perdo-nober-rs avatar Feb 02 '24 21:02 perdo-nober-rs