CS: APP The first chapter notes

CS: APP Chapter I: Roaming computer system

1. The context information is the bit +

The life cycle of a program from a source (source files) began. While the source file is a bit sequence consisting of 0 and 1, 8 bits are organized into a group, called a byte . Each byte represents some text characters in the program. Such as ASCII code table

2. The program is translated into a different format other programs

hello.c (source files) -------> hello (the target file)

We need to go through four stages:

1) pre-processing stage :

Preprocessor (CPP) in accordance with the beginning of the command character #, modify the original program, acquiring header file contents, and inserted directly into the program text, to give another program. hello.c ------> hello.i

2) compile phase :

The compiler (ccl) text file hello.i translated into assembly language text file hello.s. I.e. hello.s each statement in a text format described by a low-level machine language instructions.

3) compilation stage :

Assembler (as) the real hello.s translated into machine language instructions, and packaged into relocatable object program format, and the result is stored in the hello.o. hello.o is a binary file .

4) the link stage :

Linker (LD) in the case of certain functions to process a single pre-compiled object files, and their linker hello.o combined to generate executable object file may be loaded into memory for execution system.

3. The processor reads and interprets the instructions stored in the memory

3.1 System hardware composition

(1). Bus

Throughout the electronic system is a set of pipes, to become the bus. Bus is usually designed to transmit a byte fixed-length blocks, i.e. the word. (I.e., the number of bytes transmitted over the bus is a word). Word is the number of bytes in a system parameter, it is not fixed but may be 4-byte (32-bit), it may be 8 bytes (64 bits)

(2) I / O devices

Each I / O device or adapter through a controller / O is connected to the I bus. The main difference between the controller and the adapter is that their packages, the controller on the motherboard chipset, and the adapter is a card plugged into the motherboard.

(3) main memory

Main memory is a temporary memory to store data and programs while processing a program executed by a processor. Physically speaking, a set of main memory is a dynamic random access memory (DRAM) composed of a chip. Logically, the memory is a linear array of bytes, each byte has its own unique address, the address is zero.

(4) Processor

A central processing unit (CPU), referred to as a processor, is interpreted (or executed) Engine instructions stored in main memory. Core processor is a word size of a memory device (register), referred to as a program counter (PC). PC at any time point to a machine language instruction in the main memory (i.e., containing the address of the instruction).

CPU there are two important components. Register file and arithmetic / logic unit (ALU). Register file is a small storage device, by a number of single word registers, each register has a unique name. ALU to calculate a new data and address values.

The cache is crucial

Often you need to copy the data in the course of the program running everywhere, which can cause a lot of overhead, and main memory and register access speeds vary greatly, which resulted in a slow down of.

For such a difference in speed between the main memory and the processor, cache register (Cache) is designed as a temporary staging area, the information stored in the near future will likely be needed. Using a physical cache static random access memory (the SRAM) , by using the principle of locality of program logic, i.e. program sections, have a tendency to access the local data and code.

(Using a programmer may utilize existing high-speed cache memory to improve performance of the program an order of magnitude)

6. An apparatus for forming a storage hierarchy

7.操作系统管理硬件

操作系统有两个基本功能:

1)防止硬件被失控的应用程序滥用

2)向应用程序提供简单一致的机制来控制复杂而又通常不相同的低级硬件设备。

操作系统通过进程,虚拟内存和文件这几个抽象概念来实现这两个功能。

7.1.进程

当hello这样的程序运行时,操作系统会提供一种假象,就好像系统中只有一个程序在运行。这个假象就是通过进程来实现的。

进程是操作系统对一个正在运行的程序的一种抽象,在一个系统上可以同时运行多个进程,而每个进程都好像独立的占用硬件。而并发运行,则是说一个进程的指令和另一个进程的指令是交错进行的。操作系统实现这种交错执行的机制称为上下文切换。操作系统保持跟踪进程运行所需要的所有状态信息,这种状态就是上下文,包括许多信息,比如PC寄存器文件的当前值和主存的内容。

当操作系统决定把控制权从当前此进程转移到新的进程时,就会进行上下文切换,即保存当前进程的上下文,恢复新进程的上下文,然后将控制权转移到新进程,新进程就会从他上次停止的地方开始。

从一个进程到另一个进程的转换是由操作系统内核管理的,内核是操作系统代码常驻主存的部分。

当应用程序需要操作系统的某些操作时,比如读写文件,他就执行一条特殊的系统调用指令,将控制权转移给内核。然后内核执行被请求的操作并返回应用程序。(内核并不是一个独立的进程,相反,他是系统管理全部进程所有的代码和数据结构的集合。

7.2 线程

一个进程实际上可以由多个称为线程的执行单元组成,每个线程都运行在进程的上下文中,并共享同样的代码和全局数据。多线程比多进程之间更同意共享数据,也更高效

7.3虚拟内存

虚拟内存是一个抽象概念,它为每个进程提供了一个假象,即每一个进程都在独占地使用主存。每个进程看到的内存都是一致的,称为虚拟地址空间。

 

 

 

7.4 文件

文件就是字节序列,I/O设备都能堪称文件。是一种抽象的表示方法,方便程序员“一视同仁”

8 本章主要的抽象:

1)文件是对I/O设备的抽象

2)虚拟内存是对程序储存器的抽象

3)进程是对一个正在运行的程序的抽象

4)虚拟机是对整个计算机的抽象

 

Guess you like

Origin www.cnblogs.com/AlanHe/p/11627655.html