4 ms·
> ...wouldn't passing the return value on the stack also allow reentrancy? Passing args and return values in registers instead of on the stack would definitely
by ikari_pl 3y ago
> ...wouldn't passing the return value on the stack also allow reentrancy? Passing args and return values in registers instead of on the stack would definitely be faster, and on 8-bit CPUs, every clock cycle mattered.
But stack is memory. At least in these systems. So I think the problems could rise if we would throw concurrency into the picture, where you also have to synchronize the memory access, maybe?
- flohofwoe 3y agoSwitching to a different "thread" would also switch to a different stack though (although that would be kinda tricky on a 6502 where the stack is hardwired to the $100 page). Actual multithreading on an 8-bit CPU is a bit of an esoteric topic though, usually one only has to deal with interrupt service routines running concurrently :)
- Jare 3y agoYou're already using the stack for parameters without compromising reentrancy; using the stack for the return value is trivial. Just like parameters, it's easier and faster to use registers where possible in those old systems.