slug
type
status
category
summary
date
tags
password
icon
 

The fetch decode execute cycle

NARRATOR: Welcome to the central processing unit, otherwise known as CPU city.
I’ll show you how the city carries out the fetch-decode-execute cycle. Everything begins when a program has to run. These buildings are called registers. They’re like government administration offices.
All information flowing through the city passes through one of these buildings. Data, addresses, program instructions, all registered here.
The first register to get going is called the program counter. As you can see it’s set to zero, which represents an address. But before we visit that address, we need to know how information moves around the city. These pathways are called buses. They carry digital signals around CPU city. There are different types of buses and each type has a different purpose. The Address bus carries addresses. The Data bus carries data. And the control bus carries control instructions issued by this place, the Control Unit. It’s the centre of operations. It receives and decodes instructions, then sends out commands to the other components to get those instructions executed. So the first thing CPU city needs, are those instructions. It gets them from outside of the city, from this place; the memory.
The memory is the library where data is kept in the form of a computer program. CPU city can store data here as well as fetch from it.
As you can see, there are only a few lines of written code currently being stored here. Bear in mind that a modern computer can store billions of lines of code. The fetch decode execute cycle begins when the memory address held in the program counter is sent on the address bus from the program counter to the Memory Address Register. This is where we hold the memory address of the next data value or instruction which is going to be fetched or stored. At the moment, the memory address is address zero. The zero is then sent to the memory on the address bus with the aim of fetching some data that CPU city can work on. When it reaches address zero, the program instruction stored there is copied onto the data bus, and carried back to CPU city. Because the instruction is data, and not an address, it’s loaded into the Memory Data Register, which holds values and instructions until they are ready to be used by the CPU. It also holds values while they are waiting to be sent to the memory. And as LOAD 3 is an instruction, it’s automatically copied from the Memory Data Register into the current instruction register which holds instructions ready to be executed. The instruction is finally copied over to the control unit.
Before it completes the fetch stage, the control unit sends out an instruction to increment the address in the program counter, moving it up one digit. So that once the fetch-decode-execute cycle is complete, the program counter will be loaded and ready with the next memory location it needs to start the next cycle. And with that, the fetch stage is complete. Now starts the decode stage.
The control unit decodes the instruction LOAD 3 to mean LOAD the value at memory location 3 into this place, the Accumulator. The accumulator is another special purpose register. It’s like a warehouse where data is temporarily stored while mathematical and logical operations are performed by this place ... the Arithmetic Logic Unit, it is the factory of the city, and uses data stored in the accumulator to process calculations. So now that the Control Unit has decoded the instruction, the decode stage is complete. The control unit can now tell the other components to execute the program instruction, and we’re into the execute stage of the cycle. The 3 in LOAD 3 is an address, so the control unit first updates the Memory Address Register ... then a signal is sent to retrieve the data stored at memory address 3 … before the data there is sent back to the Memory Data register ... And finally makes its way to the Accumulator. Where that number 13 is stored, bringing the execute stage to an end, and completing the first fetch-decode-execute cycle. The next cycle begins and the whole process proceeds in much the same way. The next instruction, SUB 4, is fetched by the control unit. Now if LOAD 3 means load whatever value is at location 3 in the memory, it follows that SUB 4 means to subtract whatever value is being held at location 4 in the memory. The value at location 4 is fetched and we can see it’s the number 8. It gets loaded into the arithmetic logic unit. Now the full instruction, to subtract 8 from 13, can be executed. That number 13 gets sent to the arithmetic logic unit, which does the required calculation, before the result, 5, is sent back and stored in the accumulator. Ending the execute stage, and completing the second fetch decode execute cycle.
 
notion image
旁白:欢迎来到中央处理单元,又称为CPU城市。 我会向你展示这个城市如何执行取指-译码-执行周期。 一切从运行程序开始。这些建筑被称为寄存器。它们就像政府行政办公室。 所有流经这个城市的信息都要经过这些建筑。数据、地址、程序指令,都在这里注册。 第一个启动的寄存器叫做程序计数器。如你所见,它被设定为零,代表一个地址。但在我们访问那个地址之前,我们需要知道信息如何在城市中移动。 这些路径称为总线。它们在CPU城市中传送数字信号。有不同类型的总线,每种类型都有不同的用途。 地址总线携带地址。数据总线携带数据。控制总线携带由这个地方,即控制单元发出的控制指令。它是操作中心。它接收并解码指令,然后向其他组件发送命令以执行这些指令。 因此,CPU城市需要的首要之物是指令。它从城市外部的这个地方获得指令;即内存。 内存是以计算机程序形式保存数据的图书馆。CPU城市可以在这里存储数据,也可以从中获取数据。 如你所见,目前这里只存储了几行编写的代码。请记住,现代计算机可以存储数十亿行代码。 当程序计数器中的内存地址被发送到地址总线上,从程序计数器发送到内存地址寄存器时,取指-译码-执行周期开始。这是我们保持下一个数据值或将要获取或存储的指令的内存地址的地方。 此时,内存地址是地址零。零随后通过地址总线发送到内存,目的是获取一些CPU城市可以处理的数据。当它到达地址零时,那里存储的程序指令被复制到数据总线上,并带回CPU城市。因为指令是数据,不是地址,所以它被加载到内存数据寄存器中,该寄存器保存值和指令,直到它们准备被CPU使用。它还在值被发送到内存时保存值。并且由于LOAD 3是一条指令,它自动从内存数据寄存器复制到当前指令寄存器,该寄存器保存准备执行的指令。指令最终被复制到控制单元。 在完成取指阶段之前,控制单元发出一个指令,增加程序计数器中的地址,将其向上移动一个数字。这样一旦取指-译码-执行周期完成,程序计数器将加载并准备好它需要开始下一个周期的下一个内存位置。随着这一点,取指阶段完成。 现在开始译码阶段。 控制单元将LOAD 3的指令解码为将内存位置3的值加载到这个地方,即累加器。 累加器是另一个特殊用途的寄存器。 它就像一个仓库,在这个地方进行数学和逻辑运算时,数据被临时存储……算术逻辑单元,它是城市的工厂,使用累加器中存储的数据来处理计算。 现在控制单元已经解码了指令,译码阶段完成。控制单元现在可以告诉其他组件执行程序指令,我们进入执行周期的执行阶段。 LOAD 3中的3是一个地址,所以控制单元首先更新内存地址寄存器……然后发送一个信号来检索存储在内存地址3的数据……在那里的数据被发送回内存数据寄存器……最终使其进入累加器。存储的数字13结束了执行阶段,并完成了第一个取指-译码-执行周期。 下一个周期开始,整个过程以几乎相同的方式进行。 下一条指令,SUB 4,由控制单元获取。 现在,如果LOAD 3的意思是加载内存位置3的任何值,那么SUB 4意味着减去内存位置4中保存的任何值。位置4的值被获取,我们可以看到它是数字8。它被加载到算术逻辑单元。 现在,减去13的8的完整指令可以执行。 数字13被发送到算术逻辑单元,进行所需的计算,然后结果5被发送回并存储在累加器中。 结束执行阶段,并完成第二个取指-译码-执行周期。
 
 

 
 

 
4e CPU7a Introduction to Assembly Language
Loading...