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.