Skip to main content
Engineering LibreTexts

5.4: The CPU

  • Page ID
    27269
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    The CPU brings together all of the components into a single package to run programs. The CPU in this text consists of two subsections, and was purposefully designed to be simple enough that the control wires (other than the clock) for each subsection of the CPU are completely separate from the other.

    The first subsection does all arithmetic and manages input/output to/from data memory. This subsection uses the control wires Clock, MemWr (write memory), ClrAC (clear $ac by setting it to 0), WriteAc (write a value to $ac), ALUSrc (choose a source for the second ALU operand, either a memory or immediate value), and ALUOpt (a 4-bit value to specify what operation to run on the ALU).

    WriteAc (write a value to $ac), ALUSrc (choose a source for the second ALU operand, either a memory or immediate value), and ALUOpt (a 4-bit value to specify what operation to run on the ALU).

    These two subsections will be looked at separately.

    Before starting, a 0 in a control wire implies do nothing, hence a noop instruction is a 2 byte 0x0000. If a wire is not being used, by default set it to 0.

    5.4.1 The CPU – Arithmetic Subsection

    The arithmetic subsection of the CPU covers the $ac register, the ALU, and the data memory. This will cover the Assembly operations clac, add, addi, sub, subi, and stor. The arithmetic subsection is shown in the following diagram.

    Figure 5-5: CPU - Arithmetic Subsection

    Screen Shot 2020-07-03 at 12.33.10 PM.png

    The clac operation selects the constant input 0x0000 using the mux in front of the $ac to set the value of the $ac. To do this, the ClrAC line to the mux is 1 (selecting 0x0000) and WriteAC line is 1. All other control lines are 0.

    For the add and sub operations, the input to the ALU is memory data, so the ALUSrc line is set to 0 to select the Mem Data. The result is stored back into the $ac, so the ClrAC line must be set to 0 to select the output from the ALU, and the WriteAC line is set to 1 to write the ALU result into the AC. The ALUOpt is set to 0000 for add, and 0001 for subtract. All other control lines are set to 0.

    For the addi and subi operations, the input to the ALU is the immediate value, fo the ALUSrc line is set to 1 to select the immediate data value. All other lines are set like the add and sub operations.

    For the stor operation, the MemWr is set to 1, which writes the value to the D port on the Data Memory to memory at the address specified at the A port (note the address comes from the immediate part of the instruction). All other control lines are set to 0.

    Some readers might be worried that there are values passed in the CPU that are not used. For example, when the stor operation is being executed a value is still calculated in the ALU, and is sent on the wire to the $ac. However, the WriteAC line is 0, so the ALU value has no effect, and is ignored. The same is true of the Mem Data value for immediate operations like addi. The Mem Data is generated, but it is ignored as the ALUSrc chooses the immediate value. Many lines are set in every instruction, and most of them are ignored, which is why using by setting all control wires to 0 a NOOP instruction does nothing.

    5.4.2 The CPU – Execution Path Subsection

    The second subsection of the CPU is the execution path, which is shown in the figure below.

    Figure 5-6: CPU - Execution Path Subsection

    Screen Shot 2020-07-03 at 12.38.10 PM.png

    As this figure shows, the value of the $pc register is used to set the read address for the instruction. This instruction is then split into the control half (bits 8-15) and the immediate value (bits 0-7). The control bits are sent to the CU to set the control wires, and the immediate value is sent to the data memory or the ALU for use in the arithmetic subsection of the CPU.

    Each time an instruction is executed, the $pc register is changed to point to the next instruction to execute. When the program is running sequentially, the next instruction in memory is selected by adding 1 to the $pc in the adder name Increment PC, and the multiplexor is set to 0 to select this instruction.

    The only time the next instruction is not selected is if the Beqz wire is high (meaning this is a beqz instruction), AND the results of the compactor are 1 (the ALU has a value of 0). When this happens, the mux selects the Branch Address, which is the immediate value from the instruction, and the program continues executing at the instruction at the new address.


    This page titled 5.4: The CPU is shared under a CC BY 4.0 license and was authored, remixed, and/or curated by Charles W. Kann III via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.

    • Was this article helpful?