4 ms·
It's worth noting that I find "unconventional" control flow like this tends to only puzzle those who started programming at the "structured" level where functio
by userbinator 10y ago
It's worth noting that I find "unconventional" control flow like this tends to only puzzle those who started programming at the "structured" level where function calls always nest neatly, and so they have never entertained the possibility of it being any different from that.
However, the machine itself doesn't have any real notion of "call" and "return", and although dedicated instructions may be provided for convenience, all a call amounts to is "remember where in the code you were, and go somewhere else" and return is "use the saved information to go back".
It then follows that, if this saved information be not precisely that of the immediately preceding call, the processor can be caused to "return" somewhere else; and that is the basis of coroutines and process switching. Call and return are simply a convenient abstraction atop the sequential instruction stream the processor executes.
- crooked-v 10y agoThis kind of thing is why every programmer should at least once try to build something fancy using only variables and GOTO statements. The classic make-your-own-game engines ZZT and MegaZeux had a lot of this; the scripts for in-game objects had no function calls or well-managed events, just GOTOs and per-object vars, and could get interrupted at any time by GOTOs triggered by other in-game objects.
- pmiller2 10y ago> This kind of thing is why every programmer should at least once try to build something fancy using only variables and GOTO statements. So, basically, assembler without a lot of fancy macros? :)