JCOMP
JCOMP
J COMPONENT
GROUP NO: 12
Slot: B2
Submitted by:
Name Registration Number
Linu Phil Mathew 21MVD0077
Krishna Sri AK 21MVD0090
Munagala Tejaswini 21MVD0100
Shreya Roy 21MVD0106
Naomi Mallik 21MVD0115
Amit Verma 21MVD0142
Date: 13/01/2022
J COMPONENT
Design of Simple Processor
AIM:
To design, write a Verilog code and verify the design by writing testbench of Simple
Processor as the Figure shown below shows a digital system that contains a number
of 9-bit registers, a multiplexer, an adder/subtractor unit, and a control unit (finite
state machine).
Each instruction can be encoded and stored in the IR register using the 9-bit format
IIIXXXYYY, where III represents the instruction, XXX gives the Rx register, and
YYY gives the Ry register. Although only two bits are needed to encode our four
instructions, we are using three bits because other instructions will be added to the
processor in later parts of this exercise. Instructions are loaded from an external
source, hence IR has to be connected to the nine bits of the DIN input, as indicated
in Figure 1. For the mvi instruction the YYY field has no meaning, and the immediate
data #D has to be supplied on the 9-bit DIN input after the mvi instruction word is
stored into IR. Some instructions, such as an addition or subtraction, take more than
one clock cycle to complete, because multiple transfers have to be performed across
the bus. The processor starts executing the instruction on the DIN input when the
Run signal is asserted and the processor asserts the ‘Done’ output when the
instruction is finished. Table 2 indicates the control signals that can be asserted in
each time
BLOCK DIAGRAM:
module multiplex10_to_1
(Reg0in,Reg1in,Reg2in,Reg3in,Reg4in,Reg5in,Reg6in,Reg7in,DIn,G,sel,bus);
input [8:0] Reg0in,Reg1in,Reg2in,Reg3in,Reg4in,Reg5in,Reg6in,Reg7in,DIn,G;
input [9:0] sel;
//input Reg0out, Reg1out, Reg2out, Reg3out, Reg4out, Reg5out, Reg6out,
Reg7out,Din_out,G_out;
output reg [8:0] bus;
always @ (sel or DIn or G)
begin
if (sel == 10'b0000000001)
bus <= DIn;
else if (sel == 10'b0000000010)
bus <= G;
else if (sel == 10'b0000000100)
bus <= Reg7in;
else if (sel == 10'b0000001000)
bus <= Reg6in;
else if (sel == 10'b0000010000)
bus <= Reg5in;
else if (sel == 10'b0000100000)
bus <= Reg4in;
else if (sel == 10'b0001000000)
bus <= Reg3in;
else if (sel == 10'b0010000000)
bus <= Reg2in;
else if (sel == 10'b0100000000)
bus <= Reg1in;
else if (sel == 10'b1000000000)
bus <= Reg0in;
else
bus <= bus;
end
endmodule
ADDER/SUBTRACTOR MODULE:
module adder_subtractor (LdA, LdG, Add_sub,data_in, clk,Z1);
input LdA, LdG, Add_sub,clk;
// Add_sub=1 add else subtract
// data_in is the output of the mux
input [8:0] data_in;
output reg [8:0] Z1;
reg [8:0] X1 ;
wire [8:0] X, Y, Z, Bus;
assign Bus = data_in;
endmodule
module PIPO1 (dout, din, ld, clk);
input [8:0] din;
input ld, clk;
output reg [8:0] dout;
/*
mv R1,R2
000 001 010
add R1,R2
001 001 010
sub R1,R2
010 001 010
*/
reg Z=9'b111111111;
reg [1:0] PS,NS;
// Registers
reg [8:0] IRin;
//=9'001001010;
reg [8:0] R0,R1,R2,R3,R4,R5,R6,R7; // 8 Internal Registers
reg [8:0] A,G; // Two registers
// State is in T0
//opcode = Data_reg [8:6];
reg En=1;
initial
begin
// Predefined Values for Register Initial values of the Register are stored here
R0 = 9'b000000001;
R1 = 9'b000000010;
R2 = 9'b000000100;
R3 = 9'b000001000;
R4 = 9'b000010000;
R5 = 9'b000100000;
R6 = 9'b001000000;
R7 = 9'b010000000;
G = 9'b111111111;
end
always @(PS,Run,Done)
begin
case(PS)
T0: begin
if(!Run)
NS <= T0;
else
begin
IRin = DIN;
opcode <= IRin[8:6];
NS <= T1;
end
end
T1: begin
if (opcode == mv)
begin
// Ryout corresponding Reg should be high
// Rx in corresponding Reg should be high
// Done 1
// mv R1,R2 R1<----- R2
Sel <= Yreg;
case(Xreg)
10'b1000000000: begin LdR0 <= 1; LdR1 <= 0; LdR2 <= 0; LdR3 <= 0; LdR4 <=0; LdR5
<= 0; LdR6 <= 0; LdR7 <= 0; R0 <= BusWires;end
10'b0100000000: begin LdR0 <= 0; LdR1 <= 1; LdR2 <= 0; LdR3 <= 0; LdR4 <=0; LdR5
<= 0; LdR6 <= 0; LdR7 <= 0; R1 <= BusWires;end
10'b0010000000: begin LdR0 <= 0; LdR1 <= 0; LdR2 <= 1; LdR3 <= 0; LdR4 <=0; LdR5
<= 0; LdR6 <= 0; LdR7 <= 0;R2 <= BusWires;end
10'b0001000000: begin LdR0 <= 0; LdR1 <= 0; LdR2 <= 0; LdR3<= 1; LdR4 <= 0;
LdR5 <= 0; LdR6 <= 0; LdR7 <= 0; R3 <= BusWires;end
10'b0000100000: begin LdR0 <= 0; LdR1 <= 0; LdR2 <= 0; LdR3 <= 0; LdR4 <= 1;
LdR5 <= 0; LdR6 <= 0; LdR7 <= 0; R4 <= BusWires;end
10'b0000010000: begin LdR0 <= 0; LdR1 <= 0; LdR2 <= 0; LdR3 <= 0; LdR4 <= 0;
LdR5 <= 1; LdR6 <= 0; LdR7 <= 0; R5 <= BusWires;end
10'b0000001000: begin LdR0 <= 0; LdR1 <= 0; LdR2 <= 0; LdR3<= 0; LdR4 <= 0;
LdR5 <= 0; LdR6 <= 1; LdR7 <= 0;R6 <= BusWires;end
10'b0000000100: begin LdR0 <= 0; LdR1 <= 0; LdR2 <= 0; LdR3 <= 0; LdR4 <= 0;
LdR5 <= 0; LdR6 <= 0; LdR7 <= 1; R7 <= BusWires;end
endcase
Done <= 1;
NS<=T1;
end
else if(opcode == add)
begin
// Ryout corresponding Reg should be high
// Rx in corresponding Reg should be high
// Done 1
// add R1,R2 R1<----R1+R2
Sel <= Xreg;
LdA <= 1;
LdG <= 0;
A <= BusWires;
Add_sub <= 1; // 1 for add
NS<=T2;
end
end
T3: begin
if(opcode == add)
begin
Done <= 1;
Sel<=10'b0000000010;
case(Xreg)
10'b1000000000: begin LdR0 <= 1; LdR1 <= 0; LdR2 <= 0; LdR3 <= 0; LdR4 <=0; LdR5
<= 0; LdR6 <= 0; LdR7 <= 0; R0 <= BusWires;end
10'b0100000000: begin LdR0 <= 0; LdR1 <= 1; LdR2 <= 0; LdR3 <= 0; LdR4 <=0; LdR5
<= 0; LdR6 <= 0; LdR7 <= 0; R1 <= BusWires;end
10'b0010000000: begin LdR0 <= 0; LdR1 <= 0; LdR2 <= 1; LdR3 <= 0; LdR4 <=0; LdR5
<= 0; LdR6 <= 0; LdR7 <= 0; R2 <= BusWires;end
10'b0001000000: begin LdR0 <= 0; LdR1 <= 0; LdR2 <= 0; LdR3<= 1; LdR4 <= 0;
LdR5 <= 0; LdR6 <= 0; LdR7 <= 0; R3 <= BusWires;end
10'b0000100000: begin LdR0 <= 0; LdR1 <= 0; LdR2 <= 0; LdR3 <= 0; LdR4 <= 1;
LdR5 <= 0; LdR6 <= 0; LdR7 <= 0; R4 <= BusWires;end
10'b0000010000: begin LdR0 <= 0; LdR1 <= 0; LdR2 <= 0; LdR3 <= 0; LdR4 <= 0;
LdR5 <= 1; LdR6 <= 0; LdR7 <= 0; R5 <= BusWires;end
10'b0000001000: begin LdR0 <= 0; LdR1 <= 0; LdR2 <= 0; LdR3<= 0; LdR4 <= 0;
LdR5 <= 0; LdR6 <= 1; LdR7 <= 0; R6 <= BusWires;end
10'b0000000100: begin LdR0 <= 0; LdR1 <= 0; LdR2 <= 0; LdR3 <= 0; LdR4 <= 0;
LdR5 <= 0; LdR6 <= 0; LdR7 <= 1; R7 <= BusWires; end
endcase
end
endmodule
module multiplex10_to_1
(Reg0in,Reg1in,Reg2in,Reg3in,Reg4in,Reg5in,Reg6in,Reg7in,DIn,G,sel,bus);
input [8:0] Reg0in,Reg1in,Reg2in,Reg3in,Reg4in,Reg5in,Reg6in,Reg7in,DIn,G;
input [9:0] sel;
//input Reg0out, Reg1out, Reg2out, Reg3out, Reg4out, Reg5out, Reg6out,
Reg7out,Din_out,G_out;
output reg [8:0] bus;
always @ (sel or DIn or G)
begin
if (sel == 10'b0000000001)
bus <= DIn;
else if (sel == 10'b0000000010)
bus <= G;
else if (sel == 10'b0000000100)
bus <= Reg7in;
else if (sel == 10'b0000001000)
bus <= Reg6in;
else if (sel == 10'b0000010000)
bus <= Reg5in;
else if (sel == 10'b0000100000)
bus <= Reg4in;
else if (sel == 10'b0001000000)
bus <= Reg3in;
else if (sel == 10'b0010000000)
bus <= Reg2in;
else if (sel == 10'b0100000000)
bus <= Reg1in;
else if (sel == 10'b1000000000)
bus <= Reg0in;
else
bus <= bus;
end
endmodule
Testbench Code:
module testbench_proc();
reg [8:0] DIN;
reg Resetn, Clock, Run;
wire Done;
wire[8:0] BusWires;
wire [9:0] Sel,Xreg, Yreg;
wire LdR0,LdR1,LdR2,LdR3,LdR4,LdR5,LdR6,LdR7,LdA,LdG,Add_sub;
proc X1 (DIN, Resetn, Clock, Run, Done, BusWires,
Sel,LdR0,LdR1,LdR2,LdR3,LdR4,LdR5,LdR6,LdR7,LdA,LdG,Add_sub,Xreg, Yreg);
initial
begin
Clock = 1'b0;
Resetn = 1'b1;
Run = 0;
#1 Run = 1;
#100 $finish;
end
initial
begin
$monitor($time,"Clock=%b, Resetn=%b, Run=%b, DIN=%b,IRin=%b,Done=%b,
BusWires=%b,
LdR0=%b,LdR1=%b,LdR2=%b,LdR3=%b,LdR4=%b,LdR5=%b,LdR6=%b,LdR7=%b,LdA=%
b,LdG=%b,Add_sub=%b,PS=%b,NS=%b,opcode=%b",Clock,Resetn,Run,DIN,testbench_pr
oc.X1.IRin,Done,BusWires,LdR0,LdR1,LdR2,LdR3,LdR4,LdR5,LdR6,LdR7,LdA,LdG,Add_s
ub, testbench_proc.X1.PS,testbench_proc.X1.NS,testbench_proc.X1.opcode);
end
initial
begin
#1 DIN = 9'b001001010;
//000 001 010 for move R1 Din read in next clock cycle
// 001 001 010 for add R1 R2
// 010 001 010 for sub R1 R2
end
endmodule
OUTPUT SCREENSHOTS:
The output screenshots from MODELSIM ALTERA is pasted as follows for the four
given operations:
MOVE OPERATION (mv):
T0 CYCLE:
T1 CYCLE:
MOVE IMMEDIATE OPERATION (mvi):
LOAD STATE:
T0 CYCLE:
T1 CYCLE:
ADDER OPERATION:
LOADING OPERATION:
T0 CYCLE:
T1 CYCLE:
T2 CYCLE:
T3 CYCLE:
SUBTRACTER OPERATION:
LOADING OPERATION:
T0 CYCLE:
T1 CYCLE:
T2 CYCLE:
T3 CYCLE:
CONCLUSION:
The processor is implemented and simulated in the MODELSIM software and the
outputs are obtained accordingly.