Computer Architecture - Project 03
Computer Architecture - Project 03
PROJECT NUMBER :3
STUDENT ID : 118001253
03. Instructions 01
The project involves the use of Verilog to construct a 32 Bit datapath and control that
implements a set of specific instructions. The instruction set that the 32 Bit datapath is required
to implement is given in the following sections along with the format of the instruction set. The
processor that is required to be designed is not pipelined and hence involves multicycles. The
first cycle will involve instruction decode, which will be responsible for determining what the
instruction is and how the instruction is required to be executed. The second cycle involves
instruction execution and writeback. Instruction execution executes the instruction according to
the way in which it was decoded and the writeback function writes the output data to a register
file as specfied by the instruction. The project is designed to incorporate five different modules
(Control Unit, Register File, ALU, Shifter and Multiplexor) which will all be later used by
another model called the processor. In the following sections, each of these modules are
explained in detail. Finally, a testbench was required to be design that will test the functionality
of all the modules designed to implement the 32 Bit datapath.
INSTRUCTIONS
The 32 Bit multicycle datapath and control is required to implement the following instructions:
Each instruction that is fed to the datapath is required to be 18 bits long. The following table
shows how the 18 bit instruction is required to be decoded by the datapath:
The datapath determines the type of the instruction and the operation it is supposed to perform by
decoding the opcode. The following table shows the list of opcodes that the datapath recognizes
and the instruction type that each opcode is decoded to:
000 ADD
001 AND
010 NAND
011 OR
100 XOR
101 XNOR
110 SLL – SHIFT LEFT LOGICAL
111 SRL – SHIFT RIGHT LOGICAL
MODULES
In order for the 32 Bit multicycle datapath to be functional, its construction involved the
designing of several modules that each performed the instructions specified by the given table of
instructions. The instruction modules were separated into three basic categories:
Module alu
The alu module contains the specifications required to control the logic and arithmetic
instructions. A mux is programmed inside the alu which selects the required output depending on
the decoding of the opcode which specifies a certain type of instruction. The alu takes two inputs
from the two source register files and produces one output after conducting certain arithmetic or
logical operations on the inputs. The output of the alu is routed to another mux which also
receives the input from the shifter. Overall, the alu consists of objects created from the logic,
adder and mux modules, each of which are required to either perform some arithmetic or logic
operation or control which operation needs to be performed. The alu design code is provided in
the appendix at the end of the report.
Adder
The adder module represents the arithmetic instruction type and was responsible for the addition
of two inputs. The verilog code for the adder module is given in the Appendix section. The
function adder takes two arguments and returns one result. Depending on the suitable opcode, the
adder will be called upon and it will take the two inputs specified by the source registers and will
display their computer sum. The adder is implemented by the ALU which contains an object of
the adder module and is controlled by the control signals provided by the control unit.
Logic
The logic module consists of all the logical operations that is required to be conducted on given
inputs. The logic module contains five different logic operations that is required to be performed
on the given inputs. These instructions are decoded by the datapath using the appropriate opcode.
The logic module takes two inputs (which are obtained by reading the two source registers) and
assigns five different outputs to five different logic operations conduction on the two inputs that
it receives. An instance of the logic module is constructed in the ALU module, which will be
later described, and the logic module operates based on the signals supplied by the control unit.
The Verilog code for the logic module is supplied in the appendix section.
Module register
The register module consists of the construction of the 32 bit register files. The register files are
read or written depending on the signals passed from the control. In the decode stage, the register
files are read and the output of the register file provides the two inputs for the alu. These two
registers are connected to the alu. The first clock edge will indicate the decode state. The decode
state will give the read signal and the output of the register file will provide the output of the two
registers. The execution stage will be enabled at the next clock cycle and it will compute the
action of the instruction. Finally, the registers are written back at the negative edge of the clock
cycle. The register files therefore perform their necessary operations depending on the signals
sent to them from the control. The register file is also responsible to supply an input to the shifter
depending upon the instructions that it receives. The full construction of the register file is given
in the appendix section containing the verilog codes.
Module shifter
The shifter module is responsible for shifting a certain value either to the left or to the right
depending on the instruction provided. The opcode is decoded into the sll or srl instruction and
the shifter module responds to the opcode by performing the specified task. The shifter takes a
value named sel. The sel value is the signal received from the control unit and is checked in the
decode stage. If sel value is set to 0, then it is recognized as a left shift and if sel is set to 1, it is
recognized as a right shift. After a left shift or a right shift is recognized, the input is shifted by
the shift amount specified by the value of shamt. An instance of the shifter module is created in
the processor module and is controlled by signals from the controller. The code written in
Verilog that describes the operation of the shifter is provided in the appendix section.
Module mux
The mux module controls the multiplexor that is connected to the ALU and the shifter and is
controlled by signals from the controller. The mux takes three values, aluSel, shifterSel and
controlSig which are the alu selection, the shifter selection and the control signal respectively. If
the control signal is 0, then the ALU selection is active and the mux takes the input from the
ALU output. If the control signal is 1, the mux selects the shifter input and acts accordingly. The
output from the mux is written back to the register file at the negative edge of the clock cycle
after the execution stage is complete. The verilog code for the design of the multiplexor that
controls the alu and the shifter is given in the appendix section as mux1.
Module control
The control module represents the control unit that is responsible for sending the appropriate
signals which enable the components of the datapath to complete the process described by the
instructions that are fed into the datapath. The control unit acts according to the successful
decoding of the instructions and the module is implemented as a state machine. The controller
depends on three states: reset, decode and execute. The controller will go to the reset state
whenever the reset signal equals 0. In the reset state, the instructions will neither be decoded nor
executed. When the signal reset = 1, the control unit will either be in the decode state or the
execute state. The decode state involves only the decoding of the instructions and the setting of
the appropriate control signals. All other modules of the machine have no function during this
state. The next clock cycle introduces the execute state. In this state, the instructions are executed
according to the way in which they were decoded and written back to the register file in the
negative edge of the clock cycle. First, the register file will read the values from the source
registers and send out the operands to be operated on. Depending on the type of instruction that
was passed, the ALU or the Shifter will be active and will act accordingly. Finally, the mux will
select the appropriate output from either the ALU or the Shifter and send it back to the register
for write back. In this way, each instruction takes two clock cycles and the whole operation
described above is controlled by the control unit which is implemented as a state machine. The
verilog design codes for the control module is provided in the appendix section.
Module processor
The processor module culminates all the other modules that have been constructed and consists
of the final wiring that connects all other modules. Instants of the alu, register file, shifter, and
mux modules are all created in the processor module. The processor module however is
instantiated in the testbench (which is described below). The processor module uses wires to
denote the interconnections between the several modules that have been constructed and hence
the processor module provides the successful operation of the datapath. The verilog code which
shows the construction of the processor module is provided at the end of the report in the
appendix section.
Module testbench
The module testbench consists of the instructions that are used to test the successful operation of
the datapath and so see if all the modules constructed are fully functional. An instance of the
processor module is created in the testbench which contains all the instructions used to test the
32 bit multicycle datapath. The code written to construct the testbench module is provided at the
end of the report in the appendix section.
Module connection
The module connection is the last module created that connects the testbench and the processor.
Instances of the testbench and the processor modules are created in this module and the
connection module acts as the bridge connecting the processor which is required to carry out the
process and the testbench which provides the instructions required to test the datapath. The code
written in verilog to construct the connection module is provided at the end of the report in the
appendix section.
TABLE OF INPUTS TO THE MACHINE
The following inputs were used in the testbench to test the performance and behavior of the 32
bit multicycle datapath. The inputs and their textual translations are as follows:
Module Alu:
module alu(op, rs, rt, aluOut);
// ADD OPERATION
if (op == 3'b000)
begin
aluOut <= (rs + rt);
end
// AND OPERATION
else if (op == 3'b001)
begin
aluOut <= (rs & rt);
end
// NAND OPERATION
else if (op == 3'b010)
begin
aluOut <= ~(rs & rt);
end
// OR OPERATION
else if (op == 3'b011)
begin
aluOut <= (rs | rt);
end
// XOR OPERATION
else if (op == 3'b100)
begin
aluOut <= (rs ^ rt);
end
// XNOR OPERATION
else if (op == 3'b101)
begin
aluOut <= (rs ~^ rt);
end
end
endmodule
Module Register:
module register(readwrite, ins, clk, muxOut, rs, rt);
initial
begin
myRegFile[0] = 1;
myRegFile[1] = 2;
myRegFile[2] = 3;
myRegFile[3] = 4;
myRegFile[4] = 5;
myRegFile[5] = 6;
myRegFile[6] = 7;
myRegFile[7] = 8;
myRegFile[8] = 9;
myRegFile[9] = 1;
myRegFile[10]= 2;
myRegFile[11]= 3;
myRegFile[12]= 4;
myRegFile[13]= 5;
myRegFile[14]= 6;
myRegFile[15]= 7;
myRegFile[16]= 8;
myRegFile[17]= 9;
myRegFile[18]= 1;
myRegFile[19]= 2;
myRegFile[20]= 3;
myRegFile[21]= 4;
myRegFile[22]= 5;
myRegFile[23]= 6;
myRegFile[24]= 7;
myRegFile[25]= 8;
myRegFile[26]= 9;
myRegFile[27]= 1;
myRegFile[28]= 2;
myRegFile[29]= 3;
myRegFile[30]= 4;
myRegFile[31]= 5;
end
endmodule
Module Shifter:
module shifter(sel, rt, ins, shifterOut);
input sel;
input [31:0] rt;
input [17:0] ins;
end
endmodule
Module Control:
module control(clk, reset, ins, op, sel, muxIn, readwrite, present, next);
always @ (present)
begin
case(present)
A:
begin
op = 3'b000;
sel = 0;
muxIn = 0;
readwrite = 0;
next<=B;
end
B:
begin
op = ins[17:15];
sel = ins[15];
if (ins[17:16] == 2'b11)
begin
muxIn <= 1;
end
else
begin
muxIn <= 0;
end
readwrite = 0;
next<=C;
end
C:
begin
op = ins[17:15];
sel = ins[15];
if (ins[17:16]==2'b11)
begin
muxIn=1;
end
else
begin
muxIn=0;
end
readwrite=1;
next<=B;
end
endcase
end
endmodule
Module Mux:
input muxIn;
input [31:0] aluOut, shifterOut;
endmodule
Module Processor:
control controlUnit (clk, reset, ins, op, sel, muxIn, readwrite, present, next);
endmodule
Module TestBench
initial
begin
end
always
#15 clk = ~clk;
Endmodule
Module Connection
module connection;
endmodule