


控制器是整个系统的指挥中枢,在控制器的控制下,运算器、存储器和输入/输出设备等功能
部件构成一个有机的整体,根据指令的要求指挥全机协调工作。控制器的基本功能是执行指令,每条指令的执行是由控制器发出的一组微操作实现的。
控制器有硬布线控制器和微程序控制器两种类型
控制器由
1)程序计数器。用于指出下一条指令在主存中的存放地址。
2)指令寄存器。用于保存当前正在执行的那条指令。
3)指令译码器。仅对操作码字段进行译码,向控制器提供特定的操作信号。
4)存储器地址寄存器。用于存放要访问的主存单元的地址。
5)存储器数据寄存器。用于存放向主存写入的信息或从主存读出的信息。
6)时序系统。用于产生各种时序信号,它们都由统一时钟(CLOCK)分频得到。
7)微操作信号发生器。
注意:CPU内部寄存器大致可分为两类:
Memory management unit (MMU)
Main article: Memory management unit
Many microprocessors (in smartphones and desktop, laptop, server computers) have a memory management unit, translating logical addresses into physical RAM addresses, providing memory protection and paging abilities, useful for virtual memory. Simpler processors, especially microcontrollers, usually don’t include an MMU.

The fundamental operation of most CPUs, regardless of the physical form they take, is to execute a sequence of stored instructions that is called a program.
The instructions to be executed are kept in some kind of computer memory.
Nearly all CPUs follow the fetch, decode and execute steps in their operation, which are collectively known as the instruction cycle.(指令周期)
After the execution of an instruction, the entire process repeats, with the next instruction cycle normally fetching the next-in-sequence instruction because of the incremented value in the program counter.
If a jump instruction was executed, the program counter will be modified to contain the address of the instruction that was jumped to and program execution continues normally.
In more complex CPUs, multiple instructions can be fetched, decoded and executed simultaneously.
This section describes what is generally referred to as the “classic RISC pipeline”, which is quite common among the simple CPUs used in many electronic devices (often called microcontrollers).
It largely ignores the important role of CPU cache, and (therefore )the access stage of the pipeline.
Some instructions manipulate the program counter rather than producing result data directly;
such instructions are generally called “jumps” and facilitate program behavior like loops, conditional program execution (through the use of a conditional jump), and existence of functions.[c]
In some processors, some other instructions change the state of bits in a “flags” register.
- Further information: Instruction set architecture § Instruction encoding
The instruction that the CPU fetches from memory determines what the CPU will do.
In the decode step, performed by binary decoder circuitry([ˈsɜrkɪtri]) known as the instruction decoder, the instruction is converted into signals that control other parts of the CPU.
The way in which the instruction is interpreted is defined by the CPU’s instruction set architecture (ISA).[e]
Often, one group of bits (that is, a “field”) within the instruction, called the opcode, indicates which operation is to be performed,
while the remaining fields usually provide supplemental information required for the operation, such as the operands.
Those operands may be specified as
a constant value (called an immediate value),
or as( the location of a value that may be a processor register or a memory) address, as determined by some addressing mode.
In some CPU designs the instruction decoder is implemented as a hardwired, unchangeable binary decoder circuit. In others, a microprogram is used to translate instructions into sets of CPU configuration signals that are applied sequentially over multiple clock pulses.
In some cases the memory that stores the microprogram is rewritable, making it possible to change the way in which the CPU decodes instructions.
CPU的主要运作原理,不论其外观,都是执行(储存于程序里的)一系列指令。
在此讨论的是遵循普遍的冯·诺伊曼结构(von Neumann architecture)设计的设备。
程序以一系列数字储存在计算机存储器中。
差不多所有的冯·诺伊曼CPU的运作原理可分为
第一阶段,提取,从程序内存中检索指令(为数值或一系列数值)。
由程序计数器指定程序存储器的位置,程序计数器保存供识别目前程序位置的数值。
换言之,程序计数器记录了CPU在目前程序里的踪迹。
提取指令之后,PC根据指令式长度增加存储器单元[iwordlength]。
指令的提取常常必须从相对较慢的存储器查找,导致CPU等候指令的送入。这个问题主要被论及在现代处理器的缓存和流水线架构(见下)。
CPU根据从存储器提取到的指令来决定其执行行为。
在解码阶段,指令被拆解为有意义的片段。
在提取和解码阶段之后,接着进入执行阶段。该阶段中,连接到各种能够进行所需运算的CPU部件。例如,要求一个加法运算,算术逻辑单元将会连接到一组输入和一组输出。输入提供了要相加的数值,而且在输出将含有总和结果。ALU内含电路系统,以于输出端完成简单的普通运算和逻辑运算(比如加法和位操作)。如果加法运算产生一个对该CPU处理而言过大的结果,在标志寄存器里,溢出标志可能会被设置(参见以下的数值精度探讨)。
最终阶段,写回,以一定格式将执行阶段的结果简单的写回。运算结果经常被写进CPU内部的寄存器,以供随后指令快速访问。在其它案例中,运算结果可能写进速度较慢,如容量较大且较便宜的主存。某些类型的指令会操作程序计数器,而不直接产生结果资料。这些一般称作“跳转”并在程序中带来循环行为、条件性执行(透过条件跳转)和函数[jumps]。许多指令也会改变标志寄存器的状态比特。这些标志可用来影响程序行为,缘由于它们时常显出各种运算结果。例如,以一个“比较”指令判断两个值的大小,根据比较结果在标志寄存器上设置一个数值。这个标志可借由随后的跳转指令来决定程序动向。
在执行指令并写回结果资料之后,程序计数器的值会递增,反复整个过程,下一个指令周期正常的提取下一个顺序指令。如果完成的是跳转指令,程序计数器将会修改成跳转到的指令地址,且程序继续正常执行。许多复杂的CPU可以一次提取多个指令、解码,并且同时执行。这个部分一般涉及“经典RISC流水线”,那些实际上是在众多使用简单CPU的电子设备中快速普及(常称为微控制器)[riscpipeline]。