Secrets under the ATL Drapes (4)

Source: Internet
Author: User
Tags command line

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.