Objective: In this lab exercise, you will use schematic design and Verilog design to implement the single-cycle datapath and control in FIGURE 5.19 (see the figure) in the text book (the index of the figure might be different if you use an old version of the book). All functional units should be designed in Verilog. Only the datapath is designed in schematic.
Single-Cycle Datapath and Control Specification: Read Section 5.3 of A Simple Implementation in the text book. This simple implementation (see the figure) covers load word (lw), store word (sw), branch equal (beq), the arithmetic-logical instructions add, sub, and, or, set on less than (slt), and immediate instructions addi, andi, ori, and set less than immediate (slti). In this design, every instruction begins execution on one clock edge and completes execution on the next clock edge.
1. Main control unit: The following truth table completely specifies the
main control function for the simple single-cycle implementation. The top
five rows gives the combinations of input signals that correspond to
the 8 opcodes that determine the control output settings. The bottom portion
of the table gives the outputs.
Input or output | Signal name | R-format | lw | sw | beq | addi | andi | ori | set less than immediate |
Inputs | Op5 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 |
Op4 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
Op3 | 0 | 0 | 1 | 0 | 1 | 1 | 1 | 1 | |
Op2 | 0 | 0 | 0 | 1 | 0 | 1 | 1 | 0 | |
Op1 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 1 | |
Op0 | 0 | 1 | 1 | 0 | 0 | 0 | 1 | 0 | |
Outputs | RegDst | 1 | 0 | x | x | 0 | 0 | 0 | 0 |
ALUSrc | 0 | 1 | 1 | 0 | 1 | 1 | 1 | 1 | |
MemtoReg | 0 | 1 | x | x | 0 | 0 | 0 | 0 | |
RegWrite | 1 | 1 | 0 | 0 | 1 | 1 | 1 | 1 | |
MemRead | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | |
MemWrite | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | |
Branch | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | |
ALUOp1 | 1 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | |
ALUOp0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 |
2. ALU control unit: The following table shows how to set the ALU
control inputs based on the 2-bit ALUOp1 and ALUOp0, the 6-bit opcode (op
field, bits 31~26), and the 6-bit function code (bits 5~0).
Instruction opcode | ALUOp | Instruction operation | opcode | Function field | Desired ALU Action | ALUcontrol input |
LW | 00 | load word | xxxxxx | xxxxxx | add | 010 |
SW | 00 | store word | xxxxxx | xxxxxx | add | 010 |
Branch equal | 01 | branch equal | xxxxxx | xxxxxx | subtract | 110 |
R-type | 10 | add | xxxxxx | 100000 | add | 010 |
R-type | 10 | subtract | xxxxxx | 100010 | subtract | 110 |
R-type | 10 | AND | xxxxxx | 100100 | and | 000 |
R-type | 10 | OR | xxxxxx | 100101 | or | 001 |
R-type | 10 | set less than | xxxxxx | 101010 | set less than | 111 |
Immediate | 11 | addi | 001000 | xxxxxx | add | 010 |
Immediate | 11 | andi | 001100 | xxxxxx | and | 000 |
Immediate | 11 | ori | 001101 | xxxxxx | or | 001 |
Immediate | 11 | set less than immediate | 001010 | xxxxxx | set less than | 111 |
Lab Requirements: Note that all functional units should be designed in Verilog. Only the datapath is created in schematic.
IMem.cell['h0] ={`LW, 5'd0, 5'd1, 16'h1000}; //lw $1, 'h1000($0) ; Mem.cell['h1000]='h335e; $1 = 'h335e;
IMem.cell['h4] ={`LW, 5'd0, 5'd2, 16'h1004}; //lw $2, 'h1004($0) ; Mem.cell['h1004]='h0d21; $2 = 'h0d21;
Back to Exercise Page of Computer Architecture Course
.