Stuck with program flow and freezing programm

What happens when a function is called? Arguments are, usually, passed by value. How does that happen? The arguments are pushed onto the stack. What happens when the stack meets the heap? Bad things.

That means I have to live with having the bit of code repeating 9 times and fill up the program memory or using the function and dealing with a stack overflow.

Is there some tutorials dealing with that so I can plan the next project a bit better in that respect.