Disassemble a simple C program

Source: Internet
Author: User

Disassemble a simple C program
Disassemble a simple C program


After reading the Linux Kernel Analysis in the Yiyun classroom, Section 1 requires a simple C program to get the assembly code and then analyze it. As long as you clarify the meaning of each Assembly instruction, you can easily proceed. The key is to understand the ideas in it.

Int g (int x) {return x + 3;} int f (int x) {return g (x);} int main () {return f (8) + 1 ;}



The loader starts execution from main. The process is (1)-(20 ), when "call f" is executed, EIP = next command address = 23 (press the address of the next command stored in EIP to stack; Set EIP to the entry address of the called function, it is equivalent to pushl EIP, movel f, and EIP.) The current status (5)

Next, execute code Block f and execute 15th commands to reach leave (equivalent to movl % ebp, % esp, popl % ebp ). At last, the ret of main will give the CPU to other programs.

 

 

 

 

 

 

 

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.