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