《
Linux
内核分析》第一周
.
计算机是如何工作的?
郝智宇
一、
存储程序计算机工作模型
冯诺依曼体系结构:
The digital computer system is binary; the computer should be executed in the order of the program.
Memory holds instructions and data, and the CPU is responsible for interpreting and executing these instructions.
2. API:
Interface between the programmer and the computer.
3. EIP:
Call RET IMP
二、
X86
汇编基础
X86CPU
的寄存器
E
开头
32
位,
R
开头
64
位。
堆栈是计算机中非常基础性的东西。
代码段、堆栈段、数据段、附加段
CPU
在实际取指令时根据
cs:eip
来准确定位一个指令。
32
位和
64
位核心机制上差别不大。
汇编指令:
Movl,pushl,popl,call,ret,leave…
AT&T
汇编格式与
Intel
格式略有不同。
Linux
内核使用的是
AT&T
汇编格式。
Pushl
:栈的位置在增长;
Popl
:栈的位置在收缩。
Esp
栈顶;
ebp
栈底。
Eip
不能直接被修改,只能
call,ret.
三、
汇编一个简单的
C
程序分析其汇编指令执行过程(实验楼环境下操作)
1. 新建一段代码,粘贴题目所给的代码段并进行修改之后,保存:
2. 以下为这段代码的汇编指令:
3. 删除掉以点(.)开头的指令之后,得到干净完整的汇编指令如下:
g:
pushl %ebp
movl %esp, %ebp
movl 8(%ebp), %eax
addl $5, %eax
popl %ebp
ret
f:
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 $10, (%esp)
call f
addl $1, %eax
leave
ret
4.分析汇编代码的工作过程中堆栈的变化如下:
(接上)
四.对“计算机是如何工作的”的理解:
Computer execution instructions are machine language, through the assembly language and high-level language programming program through the computer compiler, the program compiled into computer executable files to work, Exchange data.
The computer in the actual work project involves a large number of jump pointer operations. The computer usually executes one instruction sequentially, and if necessary, jumps to a specific address through the register, executes it, and then passes
A series of mechanisms return to their original addresses and continue to execute sequentially. In the computer, memory holds instructions and data, and the CPU is responsible for interpreting and executing these instructions.
Shi Zhiyu No reprint "Linux kernel Analysis" MOOC course http://mooc.study.163.com/course/USTC-1000029000
The first week of Linux kernel analysis How does a computer work?