Professional Documents
Culture Documents
A l l ison
Revision: August 8, 2014 C ECS 301 – CS ULB
Team Members
We are submitting our own work, and we understand severe penalties Estimated Work Hours Point Scale
will be assessed if we submit work for credit that is not our own.
1 2 3 4 5 6 7 8 9 10 4: Exemplary
3: Complete
Print Name ID Number 2: Incomplete
5%will be deducted from total score 1: Minor effort
for each day late 0: Not submitted
Print Name ID Number
Score = Points awarded (Pts) x Weight (Wt)
GRADER Total In‐Lab
Days Score
# Demonstration Wt Pts Score Grader Signature Date
Late
Demo working Integer Datapath 3
1 Documentation / Source Code 4
Testbench / Simulation-Verification 3
General Statement: Your team (2 people) is to complete the “301 16-bit RISC Processor.” This is done by
connecting the CPU_EU with a “timing and control unit” (CU) verilog module and the 256x16 Memory (developed
in lab7). The CU will be a “Moore” implementation of a finite state machine, where the outputs (control signals for
the CPU_EU and Memory) are a function of the present state. The CU will control the execution of instructions
defined for the 301 RISC Processor (see 16-bit RISC Processor specifications document).
ir_ld CPU_EU
pc_ld
pc_inc
CU pc_sel
16
IR_out
(Finite 3
ALU_Status
State
Address D_out D_in
Machine)
16 16 16
256x16
Memory
mw_en
Top‐Level and I/O and Specifications: Your “top level” verilog module will interconnect the (1) 16-bit RISC
Processor, (2) Memory, (3) Display Controller and (4) Debounce modules. The Display Controller is
to display the Address outputs and the D_in inputs from/to the CPU_EU module based upon the AD_sel
input (sw7).
Additional control signals not provided by the CU are shown below. The reset signal is to be provided to every
logic block using synchronous logic. Both the CU and CPU_EU modules are to be clocked using the “step clk”
button (debounced). The “step_mem” button (debounced), “AD_sel” and “dump_mem” signals will be used for
displaying the contents of Memory after the 301 RISC Processor executes a “Halt” instruction. Memory is
clocked with the 50Mhz FPGA board clock. Memory is to be generated (CoreGen) with the three initialization
files (e.g. ram_256x16_lab8a.coe).
Verification: To verify that all instructions of your RISC Processor are working, you must execute (by stepping
through) the instructions for all three memory modules. The binary content of the memory modules that you
will generate are shown on pages 9 to 11. Your team must complete those three pages by disassembling the
machine code, fill in the “Register Written” column (where applicable), fill in the “Final Contents” of CPU and
Memory registers that were written to by the program that is executed as well as the exact number of
instructions that were executed, including the HALT instruction.
Deliverables: Your team must turn in (1) pages 1-2 of these cover sheets, followed by (2) the print outs from all
verilog modules, logically sequenced in a “top-down” manner, starting with the “top-level” module, followed
by (3) all three memory modules (pages 9-11) completed with applicable assembly instructions, completed
“Register Written” column (where applicable), completed “Final Contents” of CPU and Memory registers along
with the number of instructions executed, and lastly, (4) the completed “Team Accountability Reporting Sheet
(p. 12).”
As always, you will be penalized for each violation related to inputs, outputs, and operation specifications.
You will be penalized for not adhering to documentation specifications of the “deliverables,” as well as
“substandard” documentation practices (i.e. meaningless or inaccurate comments, “wrap-around” in print
outs, illegible documentation, etc.).
Control Unit Design Specifications: The control signals for the CU module are described below:
Inputs:
IR_out: This is the 16-bit instruction code currently in the IR, which consists of the 4-bit opcode and three 3-bit
register select codes.
The 4-bit opcode is used in the “decode” state to determine what instruction to execute (i.e. what
“execute” state to go to).
The W_Adr, R_Adr, and S_Adr outputs will be derived from the three 3-bit register select codes, based
upon the 4-bit opcode (e.g. for “add” W_Adr = IR[8:6], R_Adr = IR[5:3] and S_Adr = IR[2:0]).
ALU_Status: These three 1-bit values are the N, Z and C status indicators from the ALU, based upon the current ALU
opcode. These 3 bit values may or may not be stored in the actual RISC Processor’s “flag register”
based upon what state the processor is current in (e.g. the “add” state versus the “store” state).
Outputs:
W_Adr: The 3-bit “Write Address” to specify which register (R0 to R7) to write to (if rw_en is asserted).
rw_en: The register file “write enable.” When rw_en=1, the register specified by W_Adr will be written to.
R_Adr: The 3-bit “R Address” to specify which register (R0 to R7) will be output from the R port of the register file.
Note that addresses for Memory registers to be read from or written to must come from the R port of the
register file.
S_Adr: The 3-bit “S Address” to specify which register (R0 to R7) will be output from the S port of the register file.
Note that data to be written to Memory must come from the S port of the register file.
Alu_Op: This is the 4-bit ALU opcode (specified in lab 6) to control which ALU operation to perform.
s_sel: If s_sel=0 the S-port of the ALU gets data from the S-port of the register file. If s_sel=1 the S-port of the
ALU gets data from the memory (i.e. the DS datapath inputs).
adr_sel: If adr_mux=0, the “Address” outputs from CPU_EU come from the PC, else they come from the R-port of
the register file.
ir_ld: If ir_ld=1 @(posedge clk), the instruction register (IR) will be loaded, presumably with an instruction from
Memory. If ir_ld=0 @(posedge clk), the IR will remain the same.
pc_ld: If pc_ld=1 @(posedge clk), PC PC + sign_extension (IR[7:0]). This operation is an addition to the
CPU_EU logic needed for jump instructions.
pc_inc: If pc_inc=1 @(posedge clk), PC PC + 1. Note that pc_ld and pc_inc are mutually exclusive outputs.
pc_sel: If pc_sel=0, inputs to the PC come from the “PC+sign_extension” logic. If pc_sel=1, the inputs to the PC
come from the Datapath (Alu_out). Refer to the PC Modifications page.
mw_en: The Memory “write enable.” If mw_en=1, the Memory register specified by the Address outputs of CPU_EU
will be written with the data on the D_Out outputs of the CPU_EU. If mw_en=0, Memory will not be written
to.
It is IMPORTANT to note that ALL of the CU outputs must be assigned values in EVERY state!
RESET: CU
FETCH: State Diagram
PC = 00h; IR M[PC]
{nf, zf, cf} = 3’b0
PC PC +1 (Partial)
SHL: JE:
R[d] R[s] << 1 if (zf==1)
{nf,zf,cf}={N,Z,C} PC PC + seIR
IR[15:9] = 78h IR[15:9] = 7Bh
LOAD:
R[d] M[ R[s1] ] HALT:
FETCH
//*******************************************************************
module cu (clk, reset, IR, N, Z, C, // control unit inputs
W_Adr, R_Adr, S_Adr, // these are
adr_sel, s_sel, // the control
pc_ld, pc_inc, pc_sel, ir_ld, // word output
mw_en, rw_en, alu_op, // fields
status); // LED outputs
//*******************************************************************
/****************************
* data structures *
****************************/
/*********************************
* 301 Control Unit Sequencer *
*********************************/
endmodule
Note that the 8-bit “status register” is used to drive the eight LED’s (LD7 to LD0) with unique patterns to display what
state the CU is in. In addition, for the execution states for all opcodes, we display the concatenation of the present
state of the flags register and the instruction opcode.
Once the RISC Processor executes a “Halt” instruction, press reset. Then set the “dump_mem” switch to “1.”
Memory will now display location M[00h]. To step through memory, just press the step_mem button to increment
the internal “mem_counter.” This will allow you to verify the address (AD_sel=1) and contents (AD_sel=0) of memory.
Lab #8 – PC Modifications
General Statement: In order for your RISC processor to be able to execute both conditional and unconditional jump
instructions, there must be some modifications to the CPU_EU module developed in Lab #7. The conditional jump
instructions require the PC to be loaded with 16-bit values that are “relative” to its current value. Almost all processors do
“relative jumps” by adding the current contents of the PC to a signed “offset.” If the offset is expressed in less bits than
the PC itself (as is usually the case) then there must be a “sign extension” of the offset to make it the same size as the PC
before the addition. The logic diagram showing the modifications that must be made to accommodate this kind of
arrangement is show below.
The sign extension function is easily done in Verilog using the “replication” operator: {n{exp}} is equal to “n” copies of
“exp” concatenated together. Thus, for example, {5{IR[7]}} = {IR[7], IR[7], IR[7], IR[7], IR[7]}. The “SignExt” logic
in the diagram becomes nothing more than one conditional assignment statement that uses the replication operator for sign
extending our 8-bit signed offset to a 16-bit signed offset that is added to the PC.
Note, all logic color coded in yellow is combinational logic, whereas all logic color coded in blue is sequential logic. Also
note that the only extra control line needed for CPU_EU is the pc_sel control for the 2-to-1 MUX.
CPU_EU
DS
Integer
Datapath
Reg_Out ALU_Out
16
16
16-bit add
1 0
pc_sel
PC_mux 16
16 16
SignExt
pc_ld
PC 8
pc_inc ir_ld
16 IR
16
1 0
adr_sel adr_mux
16 D_out D_in
Address
Final Contents of
CPU Reg’s and Memory:
R0 = R4 = M[15] =
R1 = R5 = M[16] =
R2 = R6 = M[17] =
R3 = R7 = M[18] =
Final Contents
of Memory
M[10] = M[14] =
M[11] = M[15] =
M[12] = M[16] =
M[13] = M[17] =
Final Contents
of Memory
M[10] = M[14] = M[18] =
M[11] = M[15] = M[19] =
M[12] = M[16] =
M[13] = M[17] =