Introduced
So far, we haven't discussed anything about assembly language. But if we really want to get to the bottom of the ATL, we can't avoid this, because ATL uses some low-level technology and some inline assembly language to make it smaller and faster. Here, I assume that the reader already has the basics of assembly language, so I'll just focus on my topic and not write another assembly language tutorial. If you don't have enough knowledge of assembly language, then I suggest you take a look at Matt Pietrek in February 1998 in Microsoft System Journal's article "Under the Hood", which will give you enough information about assembly language.
Now it's time to start our journey, so let's take this simple procedure as a warm-up:
Program 55.
void fun(int, int) {
}
int main() {
fun (5, 10);
return 0;
}
Now, in command line mode, compile it using the command-line compiler cl.exe. At compile time, use the-FAS switch, for example, if the name of the program is prog55:
Cl -FAs prog55.cpp
This generates a file with the same filename with the. asm extension, which contains assembly-language code for the following program. Now look at the generated output file, let's discuss the function call first. The assembly code that invokes the function looks like this:
push 10 ; 0000000aH
push 5
call ?fun@@YAXHH@Z ; fun
First, the function's arguments are placed in the stack from the right and left, and then the function is called. However, the name of the function differs from what we give, because the C + + compiler modifies the function's name by modifying the overload of the completed function. Let's change the program a little bit, overload the function, and look at the behavior of the code.
Program 56.
void fun(int, int) {
}
void fun(int, int, int) {
}
int main() {
fun(5, 10);
fun(5, 10, 15);
return 0;
}
The assembly code that calls the two functions now looks something like this:
push 10 ; 0000000aH
push 5
call ?fun@@YAXHH@Z ; fun
push 15 ; 0000000fH
push 10 ; 0000000aH
push 5
call ?fun@@YAXHHH@Z ; fun