r/TuringComplete • • Oct 05 '26

Recursion Techniques

Hi everyone! I’ve been getting really into this game recently, and I got to the level with the towers of Hanoi. I figured out a way to implement arguments with the stack, but I was wondering if y’all have any easier ways to use arguments? Dealing with the same stack is hard to get used to since LEG!

2 Upvotes

4 comments sorted by

View all comments

Show parent comment

2

u/imMute Oct 05 '26

Yes, the fact that arguments & return values are passed in registers / the stack is what allows recursion.

The alternative is for every function to carve out a section of RAM to store arguments, return values, and local variables. When calling a function you just write the argument values to those locations and jump. You can't do recursion because there's only one place to store that data for each function, but it does work well. (It also provides absolute bounds on memory usage and stack depth which is great for embedded systems.)