Skip to content

Review Chap 4

To get a task done by a computer, we need two things: (a) a computer program that specifies what the computer must do to perform the task, and (b) the computer that is to carry out the task.

  • The instruction is the smallest piece of work specified in a computer program.
  • John von Neumann proposed a fundamental model of a computer for processing computer programs in 1946. Here is it's basic components:

1692688049747.png

  • Memory

For nowadays computer: 2^34 by 8 bits.

Addressability: 8 bits.

Address space: 2^34.

Each location has 34-bit address, for n bits can represent unique ly 2^n items.

  • MAR and MDR

To write (or store) a value in a memory location, we first write the address of the memory location in the MAR (memory's address register), the value (interrogated from the computer's memory) to be stored in the MDR (memory's data register).这并不意味着 MDR 里存的不可能是个地址!

The address of that location will be written to the (MAR) and then we interrogate the computer's memory.

The information stored in the location having that address will be placed in the memory's data register (MDR).

  • Processing Unit

The actual processing of information in the computer is carried out by the processing unit. The processing unit in a modern computer can consist of many sophisticated complex functional units, each performing one particular operation.

ALU: the simplest processing unit, is the abbreviation for Arithmetic and Logic Unit, which is capable of performing basic arithmetic functions and basic logic operations.

In LC-3, ALU can perform ADD, AND, and NOT operations.

  • Each ISA has its own word length, depending on the intended use of the computer.
  • Most microprocessors today that are used in PCs or workstations have a word length of 64 bits (as is the case with Intel's "Core" processors) or 32 bits (as is the case with Intel's "Atom" processors). Even most microprocessors now used in cell phones have 64-bit word lengths, such as Apple's A7 through A11 processors, and Qualcomm's SnapDragon processors. However, the microprocessors used in very inexpensive applications often have word lengths of as little as 16 or even 8 bits.
  • LC-3 has a word length of 16 bits.
  • It is almost always the case that a computer provides some small amount of storage very close to the ALU to allow results to be temporarily stored if they will be needed to produce additional results in the near future. (They are important.)
  • The most common form of temporary storage is a set of registers.
  • Typically, the size of each register is identical to the size of values processed by the ALU; that is, they each contain one word.
  • Current microprocessors typically contain 32 registers, each consisting of 32 or 64 bits, depending on the architecture.
  • The LC-3 has eight registers (R0, R1, … R7), each containing 16 bits.

也就是一般会涉及一些寄存器来存储计算的中间结果。

  • Input and Output(好像不重要)
  • Control Unit(it is like the conductor of an orchestra)

The control unit has an instruction register to contain that instruction to keep track of which instruction is being executed. And to keep track of which instruction is to be happened next, the control unit has a register contains next instruction’s address, which is called program counter(PC).

The LC-3: An Example von Neumann Machine

Untitled

  • Two kinds of arrowheads:
  • Filled-in: denote data elements that flow along the corresponding paths.

    https://cdn.nlark.com/yuque/0/2022/png/22387144/1657687710479-37d632d3-4794-4a2b-8330-c944922c689e.png?x-oss-process=image%2Fwatermark%2Ctype_d3F5LW1pY3JvaGVp%2Csize_9%2Ctext_SXNzaGlraeS_ri3or63pm4A%3D%2Ccolor_FFFFFF%2Cshadow_50%2Ct_80%2Cg_se%2Cx_10%2Cy_10

  • Not-filled in: denote control signals that control the processing of the data elements.

    https://cdn.nlark.com/yuque/0/2022/png/22387144/1657687737528-a4ac7ebd-3c0b-4ec3-8f7a-22bd2aeb64c9.png?x-oss-process=image%2Fwatermark%2Ctype_d3F5LW1pY3JvaGVp%2Csize_9%2Ctext_SXNzaGlraeS_ri3or63pm4A%3D%2Ccolor_FFFFFF%2Cshadow_50%2Ct_80%2Cg_se%2Cx_10%2Cy_10

    MEMORY consists of the storage elements, along with the MAR for addressing individual locations and the MDR for holding the contents of a memory location on its way to/from the sotrage.

    • NOTE: the MAR and MDR each contains 16 bits, reflecting the fact that the memory address space of the LC-3 is 2^16 memory locations and the LC-3 is 16-bit addressable.

    INPUT/OUTPUT consists of a keyboard and a monitor.

    • The simplest keyboard requires two registers: a KBDR (keyboard data register) for holding the ASCII codes of keys struck and a KBSR (keyboard status register) for maintaining status information about the keys struck.
    • The simplest monitor requires two registers: a DDR (display data register) for holding the ASCII code of something to be displayed on the screen and a DSR (display status register) for maintaining associated status information.

    THE PROCESSING UNIT consists of a functional unit (ALU here) that performs arithmetic and logic operations and eight registers (R0, ... R7) for storing temporary values that will be needed in the near future as operands for subsequent instructions.

    • The LC-3 ALU can perform one arithmetic operation (addition) and two logical operations (bitwise AND and bitwise NOT).

    THE CONTROL UNIT consists of all the structures needed to manage the processing that is carried out by the computer.

    • Its most important structure is the finite state machine, which directs all the activity.
    • Note the CLK input to the finite state machine. It specifies how long each clock cycle lasts.
    • The IR (instruction register) is also an input to the finite state machine since the LC-3 instruction being processed determines what activities must be carried out.
    • The PC (program counter) is also a part of the control unit; it keeps track of the next instruction to be executed after the current instruction finishes.
    • Note that all the external outputs of the finite state machine in the figure have arrowheads that are not filled in. These outputs control the processing throughout the computer.
    • eg: ALUK: controls the operation performed in the ALU (ADD/AND/NOT) during the current clock cycle.
    • eg: GateALU: determines whether or not the output of the ALU is provided to the processor bus during the current clock cycle.
    • 即有限元状态机的所有输出都非计算数据,而是用来控制各个元件,控制指令行为的。

    Instruction Processing

    The central idea in the von Neumann model of computer processing is that the program and data are both stored as sequences of bits in the computer’s memory, and the program is executed one instruction at a time under the ditrection of the control unit.

    • The instruction is made up of two parts, the opcode(what the instruction does) and the operands(who it does it to).
    • Three kinds of instructions: operates, data movement, and control.
    • Operate instructions operate on data.
    • LC-3 has three operate instructions: ADD/AND/NOT
    • Data movement instructions move information from the processing unit to and from memory ****and to/from input/output devices.
    • The LC-3 has six data movement instruction: LD/ST.
    • Control instructions are necessary for altering the sequential processing of instructions. (比如指令间的跳转啥的)
    • An LC-3 instruction consists of 16 bits (one word), numbered from left to right, bit [15] to bit [0].
    • Bits [15:12] contain the opcode. This means there are at most 16 distinct opcodes. Actually, we use only 15 of the possible four-bit codes. One is reserved for some future use.
    • Bits [11:0] are used to figure out where the operands are.

    至于15个指令都是什么。。。我累了,翻appendix A看吧.

Untitled

  • The Instruction Cycle(Not the Clock Cycle!)

The entire sequence of steps needed to process an instruction is called the instruction cycle.

Here are the six sequential phases of the instruction cycle:

FETCH

  • The FETCH phase obtains the next instruction from memory and loads it into the IR (instruction register) of the control unit.
  • The PC contains the address of the next instruction to be processed.
  • So the FETCH do the following things:
  • Load the MAR with the contents of the PC, and simultaneously increment the PC. [one clock cycle]
  • Interrogate memory, resulting in the instruction being placed in the MDR. [one clock cycle or more]
  • Load the IR with the contents of the MDR. [one clock cycle]
  • Each of these steps is under the direction of the control unit.
  • 获取指令数据,并更新控制模块。

DECODE

  • The DECODE phase examines the instruction in order to figure out what the microarchitecture is being asked to do.
  • 依据 opcode 进行路由,找到接下来要做什么。

EVALUATE ADDRESS

  • This phase computes the address of the memory location that is needed to process the instruction.
  • For instructions that needn't deal with an address (such as ADD with bits [5] = 0), the EVALUATE ADDRESS phase is not needed.
  • 对于部分指令,它们涉及一个需要计算才能得到的地址,而这个计算过程就是在这一部执行。

FETCH OPERANDS

  • This phase obtains the source operands needed to process the instruction.

EXECUTE

  • This phase carries out the execution of the instruction.

STORE RESULT

  • The final phase of an instruction's execution. The result is written to its designated destination.
  • Not all instructions require all six phases.

Control of the Instruction Cycle

  • The instruction cycle is controlled by a synchronous finite state machine.

https://cdn.nlark.com/yuque/0/2022/png/22387144/1657770087716-bcd10ab5-5c28-45ea-af94-981a5407dbac.png?x-oss-process=image%2Fwatermark%2Ctype_d3F5LW1pY3JvaGVp%2Csize_23%2Ctext_SXNzaGlraeS_ri3or63pm4A%3D%2Ccolor_FFFFFF%2Cshadow_50%2Ct_80%2Cg_se%2Cx_10%2Cy_10

  • Halting the Computer (the TRAP Instruction)

Untitled

  • If we need to stop this potentially infinite sequence of instruction cycles, we should stop the clock.
  • 就是通过自陷来委托计算机进行一些用户权限无法完成的事情。类似于将某些涉及到底层的行为封装起来,来增加安全性。
  • In the LC-3, as in many other machines, it is done under control of the operating system. For now it is enough to know that if a user program requires help from the operating system, it requests that help with the TRAP instruction (opcode = 1111) and an eight-bit code called a trap vector, which identifies the help that the user program needs. The eight-bit code x25 tells the operating system that the program has finished executing and the computer can stop processing instructions.