How the computer works
1 von Neumann architecture: A computer architecture with a stored program
Most of the devices that have computing and storage capabilities (smartphones, tablets, computers, etc.) are von Neumann architectures at the moment
- From the hardware point of view: The CPU and memory through the main line connection, the CPU on the IP (may be 16, 32, 64 bits) always point to an area of memory, the IP points to the CS (code snippet) is also in memory; The CPU always executes the instruction that the IP points to.
- From the Software View: API (Application Programming interface, with programmer) and ABI (the interface between program and CPU) are two important software interfaces.
2. x86 (32-bit) registers, low 16 bits as 16-bit register3. The stack segment registers have EBP (stack base register) and ESP (stack top pointer register). 4.64-bit CPU: In fact, with 32 bit in the core mechanism of small differences, 64 bits of the machine, the Register to RXX represents 5. Common Assembly directives
- The suffix of the b,w,l,q represents the 8,16,32,64 position respectively.
- Register addressing with% ID does not "deal" with memory
- Direct addressing & immediate number addressing
- MOVL $0x123,%eax--%eax=0x123
- MOVL 0x123,%eax--Immediate number is a hexadecimal value that begins with $. Directly accesses the data in the specified memory address (0x123) and assigns it to%eax
Variable address addressing
movl 4(%ebx),%edx//edx = *(inet_32 *)(ebx+4),即ebx的值加4之后作为一个地址,将其指向的数据赋给%edx
- Most directives have direct access to memory addresses
Homework
汇编一个简单的
C
程序分析其汇编指令执行过程:
编译结果:
删除掉以点(.)开头的指令之后,得到干净完整的汇编指令如下:
g:pushl %ebpmovl %esp, %ebpmovl 8(%ebp), %eaxaddl $6, %eaxpopl %ebpretf:pushl %ebpmovl %esp, %ebpsubl $4, %espmovl 8(%ebp), %eaxmovl %eax, (%esp)call addleaveretmain:pushl %ebpmovl %esp, %ebpsubl $4, %espmovl $6, (%esp)call faddl $1, %eaxleaveret
分析:
总结:
首先,因为是跟新电脑的磨合期解聘工具没找着,图片怎么也旋转不过来请谅解。
对“计算机是如何工作的”的理解:
我眼中的计算机是一个非常听话,中规中矩的孩子,一步步按照命令来执行,犯的错误也很少,不会耍小聪明走捷径,除非指出来。但要做到这一点就需要他的五脏六腑来协调工作。储存设备给予他空间去存储各种东西,指令负责指挥各项操作,就像人体的器官和血液一样,互相互利共生。
最后,这一学期请老刘男神多多指教啦!
李辰希 《Linux内核分析》MOOC课程http://mooc.study.163.com/course/USTC-1000029000
20135201 Li Chenxi How does the computer work in the first week of Linux kernel analysis?