von Neumann architecture
Core Ideas
1. Von Neumann is: The digital computer system is binary; the computer should be executed in the order of the program.
2. The binary system is used as the basis of computer numerical calculation, and 0 and 1 represent the value. The binary system makes it easy for the computer to calculate the numerical value without using the decimal counting method commonly used by humans.
3. The sequence of procedures or instructions, that is, pre-programmed, and then handed to the computer in accordance with the pre-defined sequence of the program to perform numerical calculations.
Five types of addressing modes in assembly language
· Register addressing Registermode:% Register For example:%edx Access register edx
· Immediate addressing immediate: $ number for example: $0x123 value 0x123
· Direct addressing directly: Numbers such as: 0x123 access address 0x123 point to memory
· Indirect addressing indirect: (% Register) (%EBX) For example: the memory in the Access register EBX the address pointed to
· Addressing displaced: offset (% register) 4 (%EBX): Accesses the address in the register EBX and adds 4 points to the memory;
A few important assembly instructions
Example instruction |
What it does |
PUSHL%eax |
Subl $4,%ESP//stack top pointer minus 4, stack grows down one position Movl%eax, (%ESP)//The memory location where the value in the EAX is placed on the top of the stack pointer |
POPL%eax |
MOVL (%ESP),%eax//from the in-memory value pointed to by the top of the stack into EAX Addl $4,%ESP//stack top pointer plus 4, stack is shrinking upward |
Call 0x12345 |
PUSHL%eip//IP Press Stack MOVL $0x12345,%EIP//0x12345 into EIP |
Ret |
POPL%eip//ip out Stack |
Use the Gcc-s-o main.s main.c-m32 command to compile the source code into assembly code. The source code is as follows:
int g(int x) { return x + 9;} int f(int x) { return g (x);} int main(void) { return F (+) + one ;}
The compiled code is as follows:
g: pushl %ebp movl %esp, %ebp movl 8(%ebp), %eax addl $9, %eax popl %ebp retf: pushl %ebp movl %esp, %ebp subl $4, %esp movl 8(%ebp), %eax movl %eax, (%esp) call g leave ret main: pushl %ebp movl %esp, %ebp subl $4, %esp movl $18, (%esp) call f addl $11, %eax leave ret
Stack change process
1.main function--PUSHL%EBP + MOVL%ESP,%EBP
2.main function--subl $4,%esp + movl $18, (%ESP)
3.main function--call F
4.f function--PUSHL%EBP + MOVL%ESP,%EBP
5.f function--subl $4,%esp + movl 8 (%EBP),%eax + movl%eax, (%ESP)
6.f function--call g
7.G function--PUSHL%ebp + movl%esp,%EBP + movl 8 (%EBP),%eax
8.G function--addl $9,%eax + popl%EBP
9.G function--ret The next step is to run the 15th line of instructions, which is the leave instruction of the F function
10.f function--leave
11.f function--ret The next step is to run the 23rd line of instructions, which is the ADDL instruction of the main function
Experiment
Huang Weiye Original works reproduced please indicate the source "Linux kernel Analysis" MOOC course http://mooc.study.163.com/course/USTC-1000029000
The first week of Linux kernel analysis-how computers work