Professional Documents
Culture Documents
Computer Architecture
SUBMMITTED BY
2019-EE-602
SUBMITTED TO
Engr. Osama Bin Naeem
Page 1 of 69
Lab 01
How to download and install Xilinx
Step 01:
Download the Xilinx ISE Design Suite v14.7 from the below link:
https://getintopc.com/softwares/design/xilinx-ise-design-suite-v14-7-free-download/
Step 02:
Extract the file which you have downloaded and then enter 123 in password to extract it.
Page 2 of 69
Step 03:
Turn off your antivirus before installation…!
Step 04:
Double click on Setup and accept all the options and click next.
Page 3 of 69
Step 05:
Wait until the installation is complete.
Step 06:
Copy the license file from the crack folder and replace it with
C:\Xilinx\14.7\ISE_DS\EDK\data\core_licenses
Page 4 of 69
Step 07:
All done! Now open the Xilinx ISE icon on the desktop and start working.
Page 5 of 69
Lab 02
Implementation of Logical Gates
Logical Gates:
A logic gate is a device that acts as a building block for digital circuits.
Different types of Gates are:
• AND Gate
• OR Gate
• Not Gate
• NAND Gate
• NOR Gate
• XOR Gate
• XNOR Gate
Page 6 of 69
Logical gates implementation in Xilinx:
To make this project follow the below instructions:
• Click on the New Project Option, name it and save it.
• Add a new file “Verilog Module” and declare inputs and outputs.
• Write the code of all logical gates and save it.
• Then in bottom left menu run “Check Syntax” in Synthesize – XST.
• Then click on View RTL Schematic to view the schematic diagram of the gates.
• Add another new file “Verilog Text Fixture”, name it and save it.
• Now edit the input values and save it.
• Click on the “Simulation” tab then run “Behavioral Check Syntax”.
• All done now click on “Simulate Behavioral Model” to run.
// Inputs
Page 7 of 69
reg a;
reg b;
// Outputs
wire o1;
wire o2;
wire o3;
wire o4;
wire o5;
wire o6;
wire o7;
initial begin
// Initialize Inputs
a = 0; b = 0;
#100 a = 0; b = 1;
#100 a = 1; b = 0;
#100 a = 1; b = 1;
end
endmodule
Page 8 of 69
Simulation:
Page 9 of 69
Lab 03
Full Adder/Subtractor and Half Adder/Subtractor
Adder/Subtractor:
Full Adder/Subtractor and Half Adder/Subtractor.
• A logic circuit used for adding two 1-bit numbers or simply two bits is called as a
Half Adder circuit.
• A Full Adder is a combinational logic circuit which performs addition on three bits
and produces two outputs: a Sum and a Carry.
• A Half Subtractor is a multiple output Combinational Logic Circuit that does the
subtraction of two 1-bit binary numbers
• A Full Subtractor is a combinational logic circuit which performs a subtraction
between the two 1-bit binary numbers and it also considers the borrow of the previous
bit i.e., whether 1 has been borrowed by the previous minuend bit.
Half Adder:
Page 10 of 69
Full Adder:
Half Subtractor:
Full Subtractor:
Page 11 of 69
• Add another new file “Verilog Text Fixture”, name it and save it.
• Now edit the input values and save it.
• Click on the “Simulation” tab then run “Behavioral Check Syntax”.
• All done now click on “Simulate Behavioral Model” to run.
input a,b,
output cout,s
);
assign s= a^b;
endmodule
module FullAdder(
input a,b,cin,
output s,cout
);
assign s= (a^b)^cin;
endmodule
module HalfSubtactor(
input a,b,
output bout,d
);
assign d=a^b;
endmodule
module FullSubtractor(
input a,b,bin,
output d,bout
);
assign d= (a^b)^bin;
endmodule
Page 12 of 69
Verilog Test Bench Code:
module HalfAdderTB;
// Inputs
reg a;
reg b;
// Outputs
wire cout;
wire s;
HalfAdder uut (
.a(a),
.b(b),
.cout(cout),
.s(s)
);
initial begin
// Initialize Inputs
a = 0; b = 0;
Page 13 of 69
#100 a = 0; b = 1;
#100 a = 1; b = 0;
#100 a = 1; b = 1;
#100;
end
endmodule
module FullAdderTB;
// Inputs
reg a;
reg b;
reg cin;
// Outputs
wire s;
wire cout;
FullAdder uut (
.a(a),
.b(b),
.cin(cin),
.s(s),
.cout(cout)
);
initial begin
// Initialize Inputs
a = 0; b = 0; cin = 0;
#100 a = 1; b = 0; cin = 0;
#100 a = 0; b = 1; cin = 0;
#100 a = 1; b = 1; cin = 0;
#100 a = 0; b = 0; cin = 1;
#100 a = 1; b = 0; cin = 1;
#100 a = 0; b = 1; cin = 1;
#100 a = 1; b = 1; cin = 1;
Page 14 of 69
// Wait 100 ns for global reset to finish
#100;
end
endmodule
module HalfSubtractorTB;
// Inputs
reg a;
reg b;
// Outputs
wire bout;
wire d;
HalfSubtactor uut (
.a(a),
.b(b),
.bout(bout),
.d(d)
);
initial begin
// Initialize Inputs
a = 0; b = 0;
#100 a = 0; b = 1;
#100 a = 1; b = 0;
#100 a = 1; b = 1;
#100;
end
endmodule
module FullSubtractorTB;
// Inputs
reg a;
reg b;
Page 15 of 69
reg bin;
// Outputs
wire d;
wire bout;
FullSubtractor uut (
.a(a),
.b(b),
.bin(bin),
.d(d),
.bout(bout)
);
initial begin
// Initialize Inputs
a = 0; b = 0; bin = 0;
#100 a = 0; b = 0; bin = 1;
#100 a = 0; b = 1; bin = 0;
#100 a = 0; b = 1; bin = 1;
#100 a = 1; b = 0; bin = 0;
#100 a = 1; b = 0; bin = 1;
#100 a = 1; b = 1; bin = 0;
#100 a = 1; b = 1; bin = 1;
#100;
end
endmodule
Page 16 of 69
Simulation:
Page 17 of 69
Full Subtractor
Full Adder
Half Adder
Half Subtractor
Page 18 of 69
Lab 04
4-bit Adder and Subtractor
4-bit Adder/Subtractor:
Implementation using one circuit (full adder):
• A parallel adder is an arithmetic combinational logic circuit that is used to add more
than one bit of data simultaneously.
• A full adder adds two 1-bits and a carry to give an output. However, to add more than
one bit of data in length, a parallel adder is used.
• A parallel adder adds corresponding bits simultaneously using full adders.
• Simultaneously, it keeps generating a carry and pushing it towards the next most
significant bit to be added.
• An n-bit parallel adder uses n full adders connected in cascade with each full adder
adding the two corresponding bits of both the numbers.
Page 19 of 69
Verilog Module Code:
module ParallelAdderSubtractor(
output [0:3]R,
output O,
output V,
input [0:3]A,
input [0:3]B,
input M
);
wire O0;
wire O1;
wire O2;
wire O3;
wire B0;
wire B1;
wire B2;
wire B3;
endmodule
// Inputs
reg [0:3] A;
reg [0:3] B;
Page 20 of 69
reg M;
// Outputs
wire [0:3] R;
wire O;
wire V;
ParallelAdderSubtractor uut (
.R(R),
.O(O),
.V(V),
.A(A),
.B(B),
.M(M)
);
initial begin
// Initialize Inputs
A = 4'b1010; B = 4'b1001; M = 0;
#100;
end
endmodule
Page 21 of 69
Simulation:
Page 22 of 69
Lab 05
Multiplexer (MUX)
MUX:
Multiplexing is the generic term used to describe the operation of sending one or more analogue
or digital signals over a common transmission line at different times or speeds and as such, the
device we use to do just that is called the multiplexer.
• The multiplexer, shortened to “MUX” or “MPX”, is a combinational logic circuit
designed to switch one of several input lines through to a single common output line
by the application of a control signal.
• Multiplexers operate like very fast acting multiple position rotary switches connecting
or controlling multiple input lines called “channels” one at a time to the output.
• Multiplexers, or MUX’s, can be either digital circuits made from high speed logic
gates used to switch digital or binary data or they can be analogue types using
transistors, MOSFET’s or relays to switch one of the voltage or current inputs
through to a single output.
4 to 1 MUX implementation:
To make this project follow the below instructions:
• Click on the New Project Option, name it and save it.
• Add a new file “Verilog Module” and declare inputs and outputs.
• Write the code of 4 to 1 MUX and save it.
• Then in bottom left menu run “Check Syntax” in Synthesize – XST.
• Then click on View RTL Schematic to view the schematic diagram of the gates.
• Add another new file “Verilog Text Fixture”, name it and save it.
• Now edit the input values and save it.
• Click on the “Simulation” tab then run “Behavioral Check Syntax”.
• All done now click on “Simulate Behavioral Model” to run.
Page 23 of 69
Verilog Module Code:
module MUX4_1(
input a,b,c,d,s0,s1,
output y
);
assign y= (~s0&~s1&a)|(~s0&s1&b)|(s0&~s1&c)|(s0&s1&d);
endmodule
// Inputs
reg a;
reg b;
reg c;
reg d;
reg s0;
reg s1;
// Outputs
wire y;
MUX4_1 uut (
.a(a),
.b(b),
.c(c),
.d(d),
.s0(s0),
.s1(s1),
.y(y)
);
initial begin
// Initialize Inputs
a = 0; b = 0; c = 0; d = 0; s0 = 0; s1 = 0;
#100 a = 0; b = 0; c = 0; d = 1; s0 = 0; s1 = 1;
#100 a = 0; b = 0; c = 1; d = 0; s0 = 1; s1 = 0;
Page 24 of 69
#100 a = 0; b = 0; c = 1; d = 1; s0 = 1; s1 = 1;
#100 a = 0; b = 1; c = 0; d = 0; s0 = 0; s1 = 0;
#100 a = 0; b = 1; c = 0; d = 1; s0 = 0; s1 = 1;
#100 a = 0; b = 1; c = 1; d = 0; s0 = 1; s1 = 0;
#100 a = 0; b = 1; c = 1; d = 1; s0 = 1; s1 = 1;
#100 a = 1; b = 0; c = 0; d = 0; s0 = 0; s1 = 0;
#100 a = 1; b = 0; c = 0; d = 1; s0 = 0; s1 = 1;
#100 a = 1; b = 0; c = 1; d = 0; s0 = 1; s1 = 0;
#100 a = 1; b = 0; c = 1; d = 1; s0 = 1; s1 = 1;
#100 a = 1; b = 1; c = 0; d = 0; s0 = 0; s1 = 0;
#100 a = 1; b = 1; c = 0; d = 1; s0 = 0; s1 = 1;
#100 a = 1; b = 1; c = 1; d = 0; s0 = 1; s1 = 0;
#100 a = 1; b = 1; c = 1; d = 1; s0 = 1; s1 = 1;
#100;
end
endmodule
Page 25 of 69
Simulation:
Page 26 of 69
Lab 06
Barrel Shifter
Barrel Shifter:
A barrel shifter is a specialized digital electronic circuit with the purpose of shifting an entire
data word by a specified number of bits by only using combinational logic, with no sequential
logic used.
• Barrel shifters are specialized electronic circuits used to shift the bits of binary data
and often employed by embedded digital signal processors and other general-purpose
processors in order to manipulate data.
• Data shifting is required for various low-level data applications such as floating-point
arithmetic operations, bit indexing and variable-length coding.
• A barrel shifter is able to complete the shift in a single clock cycle, giving it a great
advantage over a simple shifter which can shift n bits in n clock cycles.
• It is used in conjunction with a processor’s arithmetic logic unit (ALU) or otherwise
embedded in the ALU itself.
Page 27 of 69
Verilog Module Code:
module BarelShifter(
);
Page 28 of 69
mux2X1 ins_00 (.in0(y[0]),.in1(y[1]),.sel(ctrl[0]),.out(out[0]));
endmodule
// Inputs
// Outputs
BarelShifter uut (
.in(in),
.ctrl(ctrl),
.out(out)
);
initial begin
// Initialize Inputs
#100;
end
endmodule
Page 29 of 69
Simulation:
Page 30 of 69
Lab 07
Register File
Register File:
A register file is a means of memory storage within a computer's central processing unit (CPU).
• The computer's register files contain bits of data and mapping locations.
• These locations specify certain addresses that are input components of a register file.
Other inputs include data, a read and write function and execute function.
• When a user installs a program on a computer, that software application writes a
register file on the CPU.
• Most software programs will contain more than one file.
• Those files contain execution instructions that the CPU follows when the user
launches and uses the application.
Page 31 of 69
Verilog Module Code:
module RegFile(Ip1,sel_i1,Op1,sel_o1,Op2,sel_o2,RD,WR,rst,EN,clk);
input RD,WR;
input EN,clk,rst;
integer i;
wire sen;
begin
if (EN == 1)
begin
begin
end
Op1 = 32'hx;
end
begin
case ({RD,WR})
2'b00: begin
end
end
Page 32 of 69
Op2 = regFile [sel_o2];
end
end
end
endcase
end
else;
end
else;
end
endmodule
// Inputs
reg RD;
reg WR;
reg rst;
reg EN;
reg clk;
// Outputs
RegFile uut (
Page 33 of 69
.Ip1(Ip1),
.sel_i1(sel_i1),
.Op1(Op1),
.sel_o1(sel_o1),
.Op2(Op2),
.sel_o2(sel_o2),
.RD(RD),
.WR(WR),
.rst(rst),
.EN(EN),
.clk(clk)
);
initial begin
// Initialize Inputs
Ip1 = 32'b0;
sel_i1 = 4'b0;
sel_o1 = 4'b0;
sel_o2 = 4'b0;
RD = 1'b0;
WR = 1'b0;
rst = 1'b1;
EN = 1'b0;
clk = 1'b0;
#100;
rst = 1'b0;
EN = 1'b1;
#20;
WR = 1'b1;
RD = 1'b0;
Ip1 = 32'habcd_efab;
sel_i1 = 4'h0;
#20;
Page 34 of 69
Ip1 = 32'h0123_4567;
sel_i1 = 4'h1;
#20;
WR = 1'b0;
RD = 1'b1;
sel_o1 = 4'h0;
sel_o2 = 4'h1;
end
always begin
#10;
clk = ~clk;
end
endmodule
Simulation:
Page 35 of 69
Page 36 of 69
Lab 08
Arithmetic-Logical Unit
ALU:
In the computer system, ALU is a main component of the central processing unit, which stands
for arithmetic logic unit and performs arithmetic and logic operations.
• It is also known as an integer unit (IU) that is an integrated circuit within a CPU or
GPU, which is the last component to perform calculations in the processor.
• It has the ability to perform all processes related to arithmetic and logic operations
such as addition, subtraction, and shifting operations, including Boolean comparisons
(XOR, OR, AND, and NOT operations).
• Also, binary numbers can accomplish mathematical and bitwise operations. The
arithmetic logic unit is split into AU (arithmetic unit) and LU (logic unit).
• The operands and code used by the ALU tell it which operations have to perform
according to input data.
• When the ALU completes the processing of input, the information is sent to the
computer's memory.
ALU implementation:
To make this project follow the below instructions:
• Click on the New Project Option, name it and save it.
• Add a new file “Verilog Module” and declare inputs and outputs.
• Write the code of ALU and save it.
• Then in bottom left menu run “Check Syntax” in Synthesize – XST.
• Then click on View RTL Schematic to view the schematic diagram of the gates.
• Add another new file “Verilog Text Fixture”, name it and save it.
• Now edit the input values and save it.
• Click on the “Simulation” tab then run “Behavioral Check Syntax”.
• All done now click on “Simulate Behavioral Model” to run.
Page 37 of 69
Verilog Module Code:
module alu(
);
always @(*)
begin
case(ALU_Sel)
4'b0000: // Addition
ALU_Result = A + B ;
4'b0001: // Subtraction
ALU_Result = A - B ;
4'b0010: // Multiplication
ALU_Result = A * B;
4'b0011: // Division
ALU_Result = A/B;
ALU_Result = A<<1;
ALU_Result = A>>1;
ALU_Result = {A[6:0],A[7]};
ALU_Result = {A[0],A[7:1]};
ALU_Result = A & B;
Page 38 of 69
4'b1001: // Logical or
ALU_Result = A | B;
ALU_Result = A ^ B;
ALU_Result = (A>B)?8'd1:8'd0 ;
ALU_Result = (A==B)?8'd1:8'd0 ;
default: ALU_Result = A + B ;
endcase
end
endmodule
// Inputs
reg [7:0] A;
reg [7:0] B;
// Outputs
wire CarryOut;
integer i;
alu uut (
.A(A),
.B(B),
.ALU_Sel(ALU_Sel),
Page 39 of 69
.ALU_Out(ALU_Out),
.CarryOut(CarryOut)
);
initial begin
// Initialize Inputs
A = 8'h0A;
B = 4'h02;
ALU_Sel = 4'h0;
for (i=0;i<=15;i=i+1)
begin
#10;
end;
A = 8'hF6;
B = 8'h0A;
end
endmodule
Simulation:
Page 40 of 69
Page 41 of 69
Lab 09
R-Type 32 Bit Instruction
R-Type instruction:
In computer architecture, R-Type (Register Type) instruction is a type of machine
instruction that operates on registers. These instructions are used in many computer architectures,
including the MIPS architecture used in the example code we have been discussing. An R-Type
instruction typically consists of an opcode (operation code) and three register operands: one for
the source register rs1, one for the source register rs2, and one for the destination register rd. The
specific operation performed by the instruction is determined by the opcode. R-Type instructions
are typically used for operations such as arithmetic and logical operations that involve the values
stored in registers. Because these instructions operate directly on registers, they can execute very
quickly and efficiently, making them ideal for performance-critical code.
Page 42 of 69
Verilog Module Code:
module instruction (
);
opcode = instruction[6:0];
rd = instruction[11:7];
funct3 = instruction[14:12];
rs1 = instruction[19:15];
rs2 = instruction[24:20];
funct7 = instruction[31:25];
case (funct3)
default: result = 0;
endcase
end
endmodule
Page 43 of 69
Simulation:
Output Waveform:
• Both inputs are Zero:
Page 44 of 69
• Both inputs are Zero and funct3 is 001:
• Inputs are 10101 and 01011 respectively and funct3 is 001(OR operation):
• Inputs are 10101 and 01011 respectively and funct3 is 000(AND operation):
Page 45 of 69
Complex Engineering Problem
Design and Implementation of 32-bit RISC-V processor with three stage pipeline
CLOs and PLOs for Complex Engineering Problem
Please state CLOs and PLOs addressed in the complex engineering problem along with
domain and level. These are the CLOs from the theory/lab course which are already defined.
5.
Naturalization
Problem Statement
In this open-ended design lab, students as a group will investigate and design a 32-bit RISCV
processor with three stage pipeline.
• Implement a processor that supports a subset of the RISC-V ISA. The designed processor
does not support all RISC-V ISA instruction, so it cannot execute most programs. However,
the processor has most parts that a real processor has: A fetch unit, decode logic, functional
Page 46 of 69
units, a register file, I/O support, access to memory, interrupt handling, hazard elimination
protocols, and CSR Support.
• Students will be implementing the data path while designing a pipelined RISC-V processor
which will work with five stages mainly, It must contain a file or block RAM of FPGA that
will be used as Random Access Memory. Memory will be 8-bits wide but the processor
accesses 32-bits (4B) for operation. It will have 32 Registers working as General Purpose
Register. While one special purpose register (Program Counter) will be used to hold the
address of the instruction. Each Register must be 32 bit wide and clock edge triggered.
• Students are required to explore different methodologies to investigate the problem and
select/develop an optimal methodology for design of the system.
Complex Engineering Problem Attributes
Page 47 of 69
WP7: Identifies limitations and implications of the WP1
Interdependence proposed solution (CLO3)
EA4: Rubrics
Consequences for
Methodically investigates different design EA1,
society and approaches and techniques to design data path of
environment EA5: EA3
pipelined microprocessor architecture. (CLO1)
Familiarity
Selects an optimal methodology to design the EA1,
control portion of a processor, and its data path
EA3
consisting of the generalpurpose register file, ALU,
the memory interface, internal registers between
stages, and multiplexers with proper justification
(CLO2)
Page 48 of 69
Complex Engineering Problem Rubrics
Latex Used
Latex not used
References
properly added in References properly
IEEE added in IEEE Format
Report If any section is
Template has not been
Format
(2 Marks) followed and formatting missing.
Template has is not properly done but
been followed with all sections have been
all required covered
sections.
Software Viva
(10 Marks) 60-90% 0-50%
100% Understanding Understanding
Understanding.
Optocouplers
used Take care of Optocouplers not
Hardware Setup voltage and current used Won’t care of
and ratings voltage and current Wrong Hardware
Wiring Perfectly rating Perfectly Circuit.
(8 Marks) hardware hardware connection
connection Clean Poor wiring
wiring
Perfectly/Minor Not
Hardware Working with not
issues in working Working/Working with
Working (10 able to fulfill few
with all constraints not able to fulfill many
Marks) constraints
fulfilled constraints
Page 49 of 69
Solution of Complex Engineering Problem
Introduction:
RISC stands for Reduced Instruction Set computer. RISC processors are widely used
processor nowadays. There are many advantages of RISC over CISC (complex instruction set
computer) architecture. Those are high performance, fixed length instruction, single cycle
execution, smaller size, and short development time. RISC design resulted in computers that
execute instructions faster than other computers built of the same technology.Complexity is at
software level rather than hardware level. One of the main advantages is pipelining which is
absent in CISC processor. Pipelining improves overall performance of RISC architecture.
MIPS stand for microprocessor without interlocked pipeline stages. It is an open source soft
processor & one of the first successful RISC architecture. MIPS are widely used in embedded
systems. MIPS processor design is based on the RISC design principle that concentrates on
load/store architecture. MIPS has already been pronoun of MIPS instruction set and MIPS
instruction set architecture. In this we use 3 stage RISC single cycle 32 bit pipelined processor
which is inspired by MIPS having large set of registers. [1]
Instruction Format:
Proposed architecture supports Two Types of instructions. These are R-type instructions and J-
type instructions. It considers two source registers, one destination register, shift value and
opcodes for instructions. [2]
Type 01: General instruction format
Page 50 of 69
r5=r6 & r7
Type: 2 Jump instruction format
Page 51 of 69
Table 2 shows how register is accessed with their opcode. Registers can be accessed like R0 as
0000000, R1 as 0000001, R2 as 0000010, R3 as 0000011, R4 as 0000100, R5 as 0000101, R6 as
0000110, R7 as 0000111, R8 as 0001000, and so on.
Page 52 of 69
Processor Control Unit Design:
Page 53 of 69
Verilog code for the RISC processor:
Verilog code for Instruction Memory:
module Instruction_Memory(
input[15:0] pc,
output[15:0] instruction
);
initial
begin
$readmemb("./test/test.prog", memory,0,14);
end
endmodule
input clk,
// write port
input reg_write_en,
//read port 1
//read port 2
);
integer i;
// write port
//reg [2:0] i;
initial begin
Page 54 of 69
for(i=0;i<8;i=i+1)
end
if(reg_write_en) begin
end
end
endmodule
input clk,
// write port
input mem_write_en,
input mem_read,
// read port
);
integer f;
initial
begin
$readmemb("./test/test.data", memory);
f = $fopen(`filename);
Page 55 of 69
"\tmemory[3] = %b\n", memory[3],
`simulation_time;
$fclose(f);
end
if (mem_write_en)
end
endmodule
output zero
);
always @(*)
begin
case(alu_control)
3'b110: result = a | b; // or
Page 56 of 69
end
default:result = a + b; // add
endcase
end
endmodule
always @(ALUControlIn)
casex (ALUControlIn)
6'b10xxxx: ALU_Cnt=3'b000;
6'b01xxxx: ALU_Cnt=3'b001;
6'b000010: ALU_Cnt=3'b000;
6'b000011: ALU_Cnt=3'b001;
6'b000100: ALU_Cnt=3'b010;
6'b000101: ALU_Cnt=3'b011;
6'b000110: ALU_Cnt=3'b100;
6'b000111: ALU_Cnt=3'b101;
6'b001000: ALU_Cnt=3'b110;
6'b001001: ALU_Cnt=3'b111;
default: ALU_Cnt=3'b000;
endcase
endmodule
input clk,
input jump,beq,mem_read,mem_write,alu_src,reg_dst,mem_to_reg,reg_write,bne,
input[1:0] alu_op,
Page 57 of 69
output[3:0] opcode
);
wire zero_flag;
wire beq_control;
// PC
initial begin
end
begin
end
// instruction memory
Instruction_Memory im(.pc(pc_current),.instruction(instr));
// multiplexer regdest
Page 58 of 69
// register file
GPRs reg_file
.clk(clk),
.reg_write_en(reg_write),
.reg_write_dest(reg_write_dest),
.reg_write_data(reg_write_data),
.reg_read_addr_1(reg_read_addr_1),
.reg_read_data_1(reg_read_data_1),
.reg_read_addr_2(reg_read_addr_2),
.reg_read_data_2(reg_read_data_2)
);
// immediate extend
alu_control ALU_Control_unit(.ALUOp(alu_op),.Opcode(instr[15:12]),.ALU_Cnt(ALU_Control));
// multiplexer alu_src
// ALU
ALU alu_unit(.a(reg_read_data_1),.b(read_data2),.alu_control(ALU_Control),.result(ALU_out),.zero(zero_flag));
// PC beq add
// beq control
// PC_beq
// PC_bne
// PC_j
Page 59 of 69
assign PC_j = {pc2[15:13],jump_shift};
// PC_next
Data_Memory dm
.clk(clk),
.mem_access_addr(ALU_out),
.mem_write_data(reg_read_data_2),
.mem_write_en(mem_write),
.mem_read(mem_read),
.mem_read_data(mem_read_data)
);
// write back
endmodule
input[3:0] opcode,
);
always @(*)
begin
case(opcode)
4'b0000: // LW
begin
reg_dst = 1'b0;
alu_src = 1'b1;
mem_to_reg = 1'b1;
reg_write = 1'b1;
mem_read = 1'b1;
Page 60 of 69
mem_write = 1'b0;
beq = 1'b0;
bne = 1'b0;
alu_op = 2'b10;
jump = 1'b0;
end
4'b0001: // SW
begin
reg_dst = 1'b0;
alu_src = 1'b1;
mem_to_reg = 1'b0;
reg_write = 1'b0;
mem_read = 1'b0;
mem_write = 1'b1;
beq = 1'b0;
bne = 1'b0;
alu_op = 2'b10;
jump = 1'b0;
end
4'b0010: // data_processing
begin
reg_dst = 1'b1;
alu_src = 1'b0;
mem_to_reg = 1'b0;
reg_write = 1'b1;
mem_read = 1'b0;
mem_write = 1'b0;
beq = 1'b0;
bne = 1'b0;
alu_op = 2'b00;
jump = 1'b0;
end
4'b0011: // data_processing
begin
Page 61 of 69
reg_dst = 1'b1;
alu_src = 1'b0;
mem_to_reg = 1'b0;
reg_write = 1'b1;
mem_read = 1'b0;
mem_write = 1'b0;
beq = 1'b0;
bne = 1'b0;
alu_op = 2'b00;
jump = 1'b0;
end
4'b0100: // data_processing
begin
reg_dst = 1'b1;
alu_src = 1'b0;
mem_to_reg = 1'b0;
reg_write = 1'b1;
mem_read = 1'b0;
mem_write = 1'b0;
beq = 1'b0;
bne = 1'b0;
alu_op = 2'b00;
jump = 1'b0;
end
4'b0101: // data_processing
begin
reg_dst = 1'b1;
alu_src = 1'b0;
mem_to_reg = 1'b0;
reg_write = 1'b1;
mem_read = 1'b0;
mem_write = 1'b0;
beq = 1'b0;
bne = 1'b0;
Page 62 of 69
alu_op = 2'b00;
jump = 1'b0;
end
4'b0110: // data_processing
begin
reg_dst = 1'b1;
alu_src = 1'b0;
mem_to_reg = 1'b0;
reg_write = 1'b1;
mem_read = 1'b0;
mem_write = 1'b0;
beq = 1'b0;
bne = 1'b0;
alu_op = 2'b00;
jump = 1'b0;
end
4'b0111: // data_processing
begin
reg_dst = 1'b1;
alu_src = 1'b0;
mem_to_reg = 1'b0;
reg_write = 1'b1;
mem_read = 1'b0;
mem_write = 1'b0;
beq = 1'b0;
bne = 1'b0;
alu_op = 2'b00;
jump = 1'b0;
end
4'b1000: // data_processing
begin
reg_dst = 1'b1;
alu_src = 1'b0;
mem_to_reg = 1'b0;
Page 63 of 69
reg_write = 1'b1;
mem_read = 1'b0;
mem_write = 1'b0;
beq = 1'b0;
bne = 1'b0;
alu_op = 2'b00;
jump = 1'b0;
end
4'b1001: // data_processing
begin
reg_dst = 1'b1;
alu_src = 1'b0;
mem_to_reg = 1'b0;
reg_write = 1'b1;
mem_read = 1'b0;
mem_write = 1'b0;
beq = 1'b0;
bne = 1'b0;
alu_op = 2'b00;
jump = 1'b0;
end
4'b1011: // BEQ
begin
reg_dst = 1'b0;
alu_src = 1'b0;
mem_to_reg = 1'b0;
reg_write = 1'b0;
mem_read = 1'b0;
mem_write = 1'b0;
beq = 1'b1;
bne = 1'b0;
alu_op = 2'b01;
jump = 1'b0;
end
Page 64 of 69
4'b1100: // BNE
begin
reg_dst = 1'b0;
alu_src = 1'b0;
mem_to_reg = 1'b0;
reg_write = 1'b0;
mem_read = 1'b0;
mem_write = 1'b0;
beq = 1'b0;
bne = 1'b1;
alu_op = 2'b01;
jump = 1'b0;
end
4'b1101: // J
begin
reg_dst = 1'b0;
alu_src = 1'b0;
mem_to_reg = 1'b0;
reg_write = 1'b0;
mem_read = 1'b0;
mem_write = 1'b0;
beq = 1'b0;
bne = 1'b0;
alu_op = 2'b00;
jump = 1'b1;
end
default: begin
reg_dst = 1'b1;
alu_src = 1'b0;
mem_to_reg = 1'b0;
reg_write = 1'b1;
mem_read = 1'b0;
mem_write = 1'b0;
beq = 1'b0;
Page 65 of 69
bne = 1'b0;
alu_op = 2'b00;
jump = 1'b0;
end
endcase
end
endmodule
input clk
);
wire jump,bne,beq,mem_read,mem_write,alu_src,reg_dst,mem_to_reg,reg_write;
wire[1:0] alu_op;
// Datapath
Datapath_Unit DU
.clk(clk),
.jump(jump),
.beq(beq),
.mem_read(mem_read),
.mem_write(mem_write),
.alu_src(alu_src),
.reg_dst(reg_dst),
.mem_to_reg(mem_to_reg),
.reg_write(reg_write),
.bne(bne),
.alu_op(alu_op),
.opcode(opcode)
);
// control unit
Control_Unit control
.opcode(opcode),
Page 66 of 69
.reg_dst(reg_dst),
.mem_to_reg(mem_to_reg),
.alu_op(alu_op),
.jump(jump),
.bne(bne),
.beq(beq),
.mem_read(mem_read),
.mem_write(mem_write),
.alu_src(alu_src),
.reg_write(reg_write)
);
endmodule
// Inputs
reg clk;
Risc_16_bit uut (
.clk(clk)
);
initial
begin
clk <=0;
`simulation_time;
$finish;
end
always
begin
#5 clk = ~clk;
end
endmodule
Page 67 of 69
Simulation:
RTL Schematics:
Schematic Diagram:
Page 68 of 69
End Result:
References
[3] M. V. L. P. Ajith Kumar, "Design of a Pipelined in MIPS," vol. 5, no. 2016, p. 126.
Page 69 of 69