Linux kernel Analysis--assembler code execution and stack changes

Source: Internet
Author: User

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

First, the experimental steps

First, the lab building this platform into the Linux system, opened the Xfce terminal to write code.

Open the Code folder with the CD Code command, put the following input in the folder, easy to download the code, in favor of the detailed analysis later.

It compiles the code by ordering the GCC main.c command, and Gcc-s-o main.s main.c–m32 to disassemble the code. The-m32 represents a 32-bit system.

Open the resulting main.s file, and delete the. * Statement to get the final, real key function of the statement.

Second, stack changes

Before and after the computer runs, the code is sorted

PUSHL%EBP

MOVL%esp,%EBP

Subl $4,%esp

Movl $9, (%ESP)

Call F

9 PUSHL%EBP

Ten Movl%esp,%EBP

Subl $4,%esp

MOVL 8 (%EBP),%eax

Movl%eax, (%ESP)

Call G

2 PUSHL%EBP

3 Movl%esp,%EBP

4 MOVL 8 (%EBP),%eax

5 Addl,%eax (eax=9+5=14)

6 POPL%EBP

7 ret

Leave

Ret

Addl%eax (eax=14+2=16)

Leave

ret    

Third, how the computer works

I think the computer is actually very mechanical in the work, it just take out from the memory of the first instruction, start to do the corresponding action. Remove the corresponding data from the memory, then the operation or other logical operation, and then send the result to the corresponding address. Then in the next instruction, repeat the same action until the end.

Linux kernel Analysis--assembler code execution and stack changes

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.