2019-2020-1 20199323 "Linux kernel principle and Analysis" in the second week of work

experiment procedure

Main.c create a file and write the contents with the vim editor

content is written with vim

and with gcc -S -o main.s main.c -m32 command compiled into assembly code results are as follows:




Stack code changes:
- a start and esp ebp reference point 0 to the stack bottom, look at the main function "push1% ebp", which is the value of the push ebp memory, the numeral value 0 into the register ebp reference numeral 1 or 4 where the Save address.
- EIP register is automatically incremented, execution move1% esp,% ebp, ebp register will also point to the location of reference numeral 1.
- eip register is automatically incremented by 1, and then subl $ 4,% esp, esp register number plus 1, minus four addresses, there is no change in the stack space.
- eip register is automatically incremented by 1, the implementation of "movl $ 3, (% esp )", placed in the immediate 3 esp register points to the position 2 of the reference, no change register, stack contents changed.
- eip register is automatically incremented by 1, performing call f, call instruction execution equivalent% EIP push1 ( )% EIP Movl F ( ) is executed call, eip register is automatically incremented by 1, after adding village register 1 is pressed into the label. 3 position and then the line number of the first command into the function f eip register.
So then another two similar functions, not one by one, the other, there are several special instruction is equivalent to an ordinary instruction.
- Call: the pushl% EIP
Movl $ 0 × 12345,% EIP
- Enter: the pushl% EBP
Movl% ESP, EBP%
- Leave: Movl% EBP, ESP%
popl% EBP
- RET: EIP popl% (*)

--- end --- restore content

Guess you like

Origin www.cnblogs.com/w741741/p/11568757.html