rexlunae wrote:
Each program is started once, so whereever you pass control to it, you have a single potential return address to store.
You should know, that normal C-programs call a lot of functions, which are part of a library - these are "programs" too ( You do not program Your own printf(...)). In the NASM-docs You can find an example, how the normal C-function-call is done. You will see, that there is a lot of data stacked. Often the local variables too, because a C-function can call itself.
If You think of the lexical levels, normally used ( a function calls a function which calls a function....), You can see, that I'm right.
Legend found it to be silly, that I store a return adress manually....
But You did not see, what this is good for! If You don't want to "return" to the adress stored on the stack ( i.e. an error occured),
You need to pop that adress "manually" or You'd go to nirwana - and in C You can't pop the stack...
My example was meant for the purpose of branching out of a procedure to anywhere without the need of restoring the stack.
The link, You gave us, lead me to one of those efforts to make C/C++ better, using assembler. This is an argument for using assembler - and not for using C !
But all this efforts are only the half way to a solution...
As I only wanted to give a scetch of a case-selection, I did not write it in C ... I think, everybody knows how to write this. The problem, I wanted to show is, that in every "higher" language ( that's why I used a scetch), there is a case selection needed again and again, when the case could be selected already. (In my example from linux there are some 100000 case-selections done per second, only to write a scanline in the right manner!)
I want to show You the problem in an other way, so that you can see how bad it is to use a "higher" language:
If you set any "mode" in a system or a program using such a language, you need to to this using a value, which represents this mode. If you want to find a fitting branch due to that mode, you need a case-selection, where certain branches are derivated from values, which represent those branches. This means, that you finally need the adress of a label to branch to - but in higher languages you can't use such an adress, because you can't do indexed jumping or calling! You need to write case selections again and again - "manually"!
Using assembler you have the choice to do that case-selection only once. Then the result is not a value representing the mode, which needs to be compared again and again, but the right adress to branch to, which You store instead of that mode-value and use in an indexed jump or call.