Computer Basics -CPU works

Reprinted:    http://blog.chinaunix.net/uid-23069658-id-3563960.html

All along, really always thought as the year when the study "Principles of Computer Organization" within the CPU as described in the book, is a combination of various logic gate device. When nanotechnology wanted to see, really you can make those devices so small it? Until you see the Intel CPU production process and the AMD chip production process described can not help feeling, the original technology is so advanced.

In this paper we have an example of the Intel CPU works to do a brief introduction, just briefly, then AMD, ARM, MIPS PowerPC you should analogy even fishes.

I remember that it was July 18, 1968, Bob - North and Gordon - Moore's new company in California, the beautiful San Francisco Bay Mountain Meadow extension of the city of Bellevue Avenue 365 fee opened . And in the hands of the company set up soon for $ 15,000 from a company called INTELCO bought the right to use the Intel name. Whereby the semiconductor giant Intel in the IT industry, began his legendary history.
   November 15, 1971, the day as a day of global IT sector is a milestone in computer science are written in many textbooks. Intel Corporation engineer Ted Hoff invented the microprocessor -4004 a world's first, this 4 microprocessor instructions, although only 45, but can only perform 50,000 instructions per second. Even smaller than in 1946, developed by the University of Pennsylvania, the US Army the world's first computer ENIAC. But it has to be much higher degree of integration, a 4004 weighs less than a cup of Division. He invented the microprocessor, the British "Economist" magazine as "one of the most influential scientists since World War II." Intel's CPU development process in the following table:



   And behind the Pentium 1,2,3 and 4, to the Core Duo, Core 2, there is no longer list them. Intel from 8086, we entered the era of the so-called x86. 80386 marks the birth of what Intel has entered the era of 32-bit microprocessor. From 80386 to the Pentium 4's CPU, IA-32 era is legendary.

   We all know that the fundamental task is CPU instruction execution, the final sequence is a string of "0" and "1" is composed of a computer. CPU can be logically divided into three modules, namely a control unit, an arithmetic unit and a storage unit, the three parts are connected by a CPU internal bus. As follows:

 

The control unit : control unit is a command and control center of the whole CPU by the instruction register IR (Instruction Register), the instruction decoder ID (Instruction Decoder), and an operation controller OC (Operation Controller) and the like, to coordinate the entire computer work extremely orderly important. It is based on user pre-programmed sequentially each instruction fetched from memory and placed in the instruction register IR to determine what action should be performed by the instruction decode (analysis), then the controller -OC operation, according to a specific timing, micro-operation control signal sent to the respective member. OC operation controller comprises main beat pulse generator, control logic matrix, a clock pulse generator, reset circuit and start-stop circuit.

Calculation means : the core of the arithmetic unit. You can perform arithmetic operations (addition and subtraction multiplier including basic and additional operation like) and logical operations (including a shift, or a logical test comparing two values). For relative control unit, the operator accepts the command and control unit is operated, i.e., all of the operations performed by the arithmetic unit is the control signal from the control unit to command, so it is execution unit.

存储单元:包括CPU片内缓存和寄存器组,是CPU中暂时存放数据的地方,里面保存着那些等待处理的数据,或已经处理过的数据,CPU访问寄存器所用的时间要比访问内存的时间短。采用寄存器,可以减少CPU访问内存的次数,从而提高了CPU的工作速度。但因为受到芯片面积和集成度所限,寄存器组的容量不可能很大。寄存器组可分为专用寄存器和通用寄存器。专用寄存器的作用是固定的,分别寄存相应的数据。而通用寄存器用途广泛并可由程序员规定其用途,通用寄存器的数目因微处理器而异。这个是我们以后要介绍这个重点,这里先提一下。

我们将上图细化一下,可以得出CPU的工作原理概括如下:

 

总的来说,CPU从内存中一条一条地取出指令和相应的数据,按指令操作码的规定,对数据进行运算处理,直到程序执行完毕为止。
   上图中我没有画总线,只是用逻辑方式对其进行呈现。原因早期Intel的微处理器,诸如8085,8086/8088CPU,普遍采用了地址总线和数据总线复用技术,即将部分(或全部)地址总线与数据总线共用CPU的一些引脚。例如8086外部地址总线有20根,数据总线复用了地址总线的前16根引脚。复用的数据总线和地址总线虽然可以少CPU的引脚数,但却引入了控制逻辑及操作序列上的复杂性。所以,自80286开始,Intel的CPU才采用分开的地址总线和数据总线。
   不管是复用还是分开,对我们理解CPU的运行原理没啥影响,上图没画总线的目的就是怕有些人太过于追求细节,一头扎下去,浮不起来,不能从宏观上藐视敌人。
   OK,总结一下,CPU的运行原理就是:控制单元在时序脉冲的作用下,将指令计数器里所指向的指令地址(这个地址是在内存里的)送到地址总线上去,然后CPU将这个地址里的指令读到指令寄存器进行译码。对于执行指令过程中所需要用到的数据,会将数据地址也送到地址总线,然后CPU把数据读到CPU的内部存储单元(就是内部寄存器)暂存起来,最后命令运算单元对数据进行处理加工。周而复始,一直这样执行下去,天荒地老,海枯枝烂,直到停电。
   
如果你对这段话还是觉得比较晕乎,那么就看我们老师是怎么讲的:
   1、取指令:CPU的控制器从内存读取一条指令并放入指令寄存器。指令的格式一般是这个样子滴:

        操作码就是汇编语言里的mov,add,jmp 等符号码;操作数地址说明该指令需要的操作数所在的地方,是在内存里还是在CPU 的内部寄存器里。
   
2、 指令译码:指令寄存器中的指令经过译码,决定该指令应进行何种操作( 就是指令里的操作码) 、操作数在哪里( 操作数的地址)。
   
3、   执行指令,分两个阶段“取操作数”和“进行运算”。
   
4、   修改指令计数器,决定下一条指令的地址。
 

 

 

关于CPU我们从宏观上把握到这个程度就OK了,后面我们会逐步进入微观阶段,依次介绍80X86寄存器及其用途,NASM汇编和AT&T的区别,以及C代码中嵌入的汇编语言的写法。之所以介绍汇编语言目的不是说用汇编去写代码,那是相当的不现实,除非你是硬件驱动工程师。稍微偏上层一点的开发人员懂点低等的东西,对自己理解整个系统的架构和原理是相当有好处的。

Guess you like

Origin www.cnblogs.com/On-my-way/p/12096321.html