So how do these things work, anyway?

Miscellaneous Forums/General Discussion/So how do these things work, anyway?

Just now I have encountered the wonders of stack traces and other such crazy degugging things involving big collections of numbers that somehow mean something. I read a quick tutorial on debugging, only to have more questions! (It did help, but I need to know why).

I know some basic terminology like what the call stack is, what the instruction pointer is... What I don't know is how and why it all ties together and how all this connects to the big jumbles of numbers that we create.

I realize that this stuff changes between processors and operating systems, but it seems the core concepts stay rather similar. Where should I look if I want to find out how this stuff works? How does a computer program get from a file full of crazy numbers to a usable interface that actually does something?

http://en.wikipedia.org/wiki/Stack_%28data_structure%29
http://en.wikipedia.org/wiki/Call_stack

Basically there aren't enough CPU registers to hold every variable (there were only 3 on the C64!) and so often you have to store the loop index or return address for a function in an area of memory where you can get it back into a register easily later on. The data is stored in a LIFO manner as nomrally you exit the inner loop first, then an outer loop etc. Sometimes you get stack overflow when you get a loop or function calling itself over and over and never exiting properly.

This thread spurred a random thought/question:

Does Blitzmax do any form of tail-call optimization for tail-recursive functions?

Basically there aren't enough CPU registers to hold every variable (there were only 3 on the C64!)
And there are only 4 on a modern PC (for comparison the Amiga had 8 (d0-d7), and the PowerPC chip has 32 (r0-r31)).

And the Amiga has 8 address registers too!