1. 程式人生 > >CHAPTER 1 ----- a tour of computer sysytems(2)

CHAPTER 1 ----- a tour of computer sysytems(2)

reads 地址 cpu mach sin sel error evel over

1.3 It pays to understand how compilation systems work

Why programmers need to understand how compilation systems work?

1)Optimizing program performance.We do need a basic understanding of machine-level code and how the compiler translation different C statements into machine code.

chapter 3 ———how compilers translate different C constructs into these languages.

chapter 5———making simple transformations to the C code that help the compiler do its job better.

chapter 6———learn the hierarchical nature of the memory system,how C compilers store data arrays in memory and how your C programs can exploit this knowledge to run more efficiently.

2)Understanding link-time errors

(鏈接時出現的錯誤).———chapter 7

3)Avoiding secuirty holes.Buffer overflow vulnerabilities (緩沖區溢出錯誤)have accounted for the majority of security holes in network and Internet servers. Too few programmers undertand the need to carefully restict the quatity and forms of data they accept from untrusted sources.A first step in learning secure programming is to understand the consequences of the way data and control information are stored on the program stack.

chapter 3———We cover the stack discipline and buffer overflow vulnerabilities as part of our study of assembly language.

1.4 Processors read and interpret instructions stored in memory

The shell(an application program) is a command-line interpreter that prints a prompt(提示符,即"linux>"),waits for you to tpye a command line,and then performs the commond.The shell loads and runs the hello program and then waits for it to terminates(because hello is not a built-in shell command).The shell then prints a prompt and wait for the next input command line.

技術分享圖片

1.4.1Hardware organization of a system

技術分享圖片

CPU:Central processing Unit;ALU:Arithmetic/Logic unit;PC:Program counter;USB:Universal Serial Bus.

Buses:Running throughtout the system is a collection of electrical conduits(電纜/電子通道) called buses that carry bytes of information back and forth between the components.Buses are typically designed to transfer fixed-sized chunks of bytes known as words.

貫穿整個系統的是一組電子管道,稱為總線,他攜帶信息字節並負責在各個部件間傳遞。

I/O devices:Input/output(I/O)devices are the system‘s connection to the external world.Each I/O devices is connected to the I/Obus by either controller or an adapter.The distinction between the two(controller and adapter) is mainly one of packaging(封裝方式).Controller are chip sets in the device itself or on the system‘s main printed circuit board (often called motherboard主板).An adapter is a card that plugs into a slot on the motherboard. Regardless,the purpose of each is to transfer information back and forth between the I/O bus and I/O device.

Main memory:it is a temporary storage device that holds both a program and the data (that) it manipulates while the processor is executing the program.Physically,main memory consist of a collection of(一組) dynamic random access memory(DRAM)chips.Logically,memory is organized as a linear array of bytes(一個線性字節數組),each with its own unique address (array index 數組索引)starting at zero(這些地址是從零開始的).

Processor:the central processing unit(CPU)is the engine that interprets(or executes)instructions stored in main memory.At its core is a word-sized storage device(or register)called the program counter(PC).At any point in time,the PC points at (contains the address of )some machine-language instrcution in main memory.

處理器是解釋(執行)存儲在主存中指令的引擎,處理器的核心是一個大小為1個字的存儲設備(寄存器),稱為程序計數器(PC)。在任何時刻,PC都指向主存中的一條機器語言的指令(即含有該指令的地址)。

A processor reads the instruction from memory pointed at by the program counter(PC),interprets the bits in the instruction,performs some simple operation dictated by the instruction(執行該指令指示的簡單操作),and then updates the PC to point to the next instruction,according ot its instruction set architecture.

the simple operation :Load:copy a byte or a word from main memory into a register,overwriting(覆蓋) the previous contents of the register;store:copy a byte or a word from a register to a location in main memory(主存的某個位置),overwriting the previous contents of that location;operate:copy the contents of two register to the ALU,perform an arithmetic operation on the two words,and store the result in a register,overwriting the previous contents of that register,jump:extract a word from the instrunction itself (從指令本身提取一個字)and copy that word into the PC,overwriting the previous value of the PC.

We can distinguish the processor‘s instruction set architecture,describing the effect of each machine-code instruction,from its microarchitecture,describing how the processor is actually implemented.

我們將處理器的指令集架構和處理器的微體系結構區分,前者描述的是每條機器代碼指令的效果,後者描述的是處理器實際的實現方式。

1.4.2Running the hello program

command from the keyboard:

技術分享圖片

load hello(Using a technique known as direct memory access,DMA,the data travels directly from disk to main memory,without passing throught the processor ):

技術分享圖片

execute:string from memory to the register file ,and from there to the display device.

技術分享圖片

1.5Caches Matter

To deal with the processor-memory gap,system designers include smaller faster storage devices called cache memories that serve as temporary staging areas for informaiton that the processor is likely to need in the near future.An L1cache on the processor chip holds tens of thousands of bytes and can be accessed nearly as fast as the register file.A larger L2 cache with hundreds of thousands to millions of bytes is connected to the processor by a special bus.It may take 5 times longer for the process to access the L2 cache than the L1 cache,but this is still 5 to10 times faster than accessing the main memory.

L1 and L2 caches are implemented with a hardware technology known as static random access memory(SRAM).some have three levels of caches:L1,L2 and L3.

The idea behind caching is that a system can get the effect of both a very large memory and a very fast one by exploiting locality,the tendency for programs to access data and code in localized regions.

技術分享圖片

1.6 Storage devices form a hierarchy

The main idea of a memory hierarchy is that storage at one level serves as a cache for storage at the next lower level.上一層的存儲器作為低一層存儲器的高速緩存。

技術分享圖片

CHAPTER 1 ----- a tour of computer sysytems(2)