The first week of Linux kernel analysis How does a computer work?

Source: Internet
Author: User

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?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.