Assembly code Analysis for simple C program generation

Source: Internet
Author: User

First, give the complete C code:

int g (int x)
{
return x+11;
}
int f (int x)
{
return g (x);
}
int main (void)
{
return F (8) +1;
}

Use command:gcc–s–o hw001.s hw001.c-m32

Corresponds to the generated IA32 assembly code:

Temporarily do not analyze with "." The beginning of the line, get the program as follows:

G:
PUSHL%EBP
MOVL%esp,%EBP
MOVL 8 (%EBP),%eax
Addl $11,%eax
POPL%EBP
Ret
F:
PUSHL%EBP
MOVL%esp,%EBP
Subl $4,%esp
MOVL 8 (%EBP),%eax
Movl%eax, (%ESP)
Call G
Leave
Ret
Main
PUSHL%EBP
MOVL%esp,%EBP
Subl $4,%esp
Movl $8, (%ESP)
Call F
Addl $,%eax
Leave
Ret

by Kunlun Snow Fox

Original works reproduced please indicate the source

"Linux kernel Analysis" MOOC course http://mooc.study.163.com/course/USTC-1000029000

Assembly code Analysis for simple C program generation

Related Article

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.