--------------------------------------------------------------------------------------------------------------- -------------------------
This article is the MOOC course http://mooc.study.163.com/course/USTC-1000029000 of Linux kernel analysis. Homework after the first lesson. Student Name: Liu Zheng
The main content of this paper is to write a simple C language program, convert it into assembly code, analyze the changes in the stack. If there is an error, please give your valuable comments, thank you.
--------------------------------------------------------------------------------------------------------------- -------------------------------------------------------
Before analyzing the code, let's talk about the basic assembly language:
1, Movl%eax,%edx//edx=eax (register addressing is memory Independent)
2, Movl $0x123,%edx//edx=0x123 (immediate addressing)
3, Movl 0x123,%edx//edx=* (int32_t *) 0x123
4, MOVL (%EBX),%edx//edx=* (int32_t *) ebx
5, MOVL 4 (%EBX),%edx//edx = * (int32_t *) (EBX+4)
6, PUSHL%eax//subl $4,%esp
Movl%eax, (%ESP)
7, Popl%eax//MOVL (%ESP),%eax
Addl $4,%esp
8, ret//POPL%EIP
I. Establishment of a C procedure and conversion to a compilation document
1. Open the Linux virtual machine and use the VI main.c command to edit the code in the editor as follows:
2. Convert it to a compilation file in a Linux virtual machine and name it MAIN.S
3, finishing get MAIN.S assembly code
second, analysis of the stack in the assembly code change situation
Iii. Summary
The basic principle of computer is stored program and program control. A sequence of instructions (called a program) and raw data that directs the operation of the computer in advance is delivered to the computer's memory via the input device. Each instruction explicitly specifies which address the computer takes from, what to do, and what address to send to. When the computer is running, the first instruction is removed from the memory, and the decoding of the controller, according to the requirement of the instruction, takes the data from the memory to perform the processing of the specified arithmetic and logic operation, and then sends the result to the memory by the address. Next, take out the second instruction and complete the specified operation under the command of the controller. Proceed accordingly. Until a stop command is encountered. The program and data storage, according to the Order of the program, step-by-step take out the instructions, automatic completion of the instructions prescribed by the computer is the most basic principle of operation. This principle was originally proposed by the Hungarian-American mathematician von Neumann in 1945, so it is called von Neumann principle. (from Baidu Encyclopedia)
Talking about the working process of computer program