verilog solution
verilog solution
Submitted by:
• Muhammad Mohsin Khan
(CMS ID: 505636)
• Shahab Khan
(CMS ID: 508429)
• Eyesha tur radia
(CMS ID: 519787)
CE-46B
Submitted to:
• Dr. Asad Mansoor Khan
Application of ICT lab report #12
OBJECTIVES:
The purpose of this lab was to learn Behavioral Modeling to design complex Logic.
TASK #01
Verilog script:
module aludesign(A,B,C,OPCODE);
always @ (*)
begin
01
Application of ICT lab report #12
if (OPCODE==0)
C = A + B;
else if (OPCODE==1)
C = A - B;
else if (OPCODE==2)
C = A | B;
else if (OPCODE==3)
C = A & B;
else if (OPCODE==4)
C = A >> B;
else if (OPCODE==5)
C = A << B;
else
C = 0 ;
end
endmodule
TEST BENCH:
MODULE TB_ ALUDESIGN;
// I NPUTS
REG [3:0] A;
REG [3:0] B;
// O UTPUTS
WIRE [3:0] C;
ALUDESIGN UUT (
.A(A),
.B(B),
.C(C),
02
Application of ICT lab report #12
.OPCODE(OPCODE)
);
INITIAL BEGIN
// I NITIALIZE INPUTS
A = 3;
B = 2;
OPCODE = 0;
#100;
A = 3;
B = 2;
OPCODE = 1;
#100;
A = 3;
B = 2;
OPCODE = 2;
#100;
A = 3;
B = 2;
OPCODE = 3;
#100;
A = 3;
03
Application of ICT lab report #12
B = 2;
OPCODE = 4;
#100;
A = 3;
B = 2;
OPCODE = 5;
#100;
// A DD STIMULUS HERE
END
ENDMODULE
OUTPUT:
04
Application of ICT lab report #12
TASK #02:
Verilog script:
MUX:
module MUX_4_x_1(in1,in2,in3,in4,sel,out);
input [7:0]in1,in2,in3,in4;
always@(*)
begin
if (sel == 0)
out = in1;
else if (sel == 1)
05
Application of ICT lab report #12
out = in2;
else if (sel == 2)
out = in3;
else
out = in4;
end
endmodule
ALU:
module ALU(A, B, OPCODE,C);
input [7:0] A, B;
case (OPCODE)
3'b000: C = A + B;
3'b001: C = A - B;
3'b010: C = A | B;
3'b011: C = A & B;
3'b100: C = A >> B;
3'b101: C = A << B;
default: C = 4'b0000;
endcase
end
endmodule
06
Application of ICT lab report #12
Calling modules:
module rom_alu(opCode,out);
input [2:0]opCode;
wire [1:0]sel1,sel2;
initial begin
ROM[0] = 8'b00000010; // 2
ROM[1] = 8'b00000100; // 4
ROM[2] = 8'b00000011; // 3
ROM[3] = 8'b00000111; // 7
end
MUX_4_x_1 mux1(ROM[0],ROM[1],ROM[2],ROM[3],sel1,res1);
MUX_4_x_1 mux2(ROM[0],ROM[1],ROM[2],ROM[3],sel2,res2);
ALU uut1(res1,res2,opCode,out);
endmodule
TEST BENCH:
module tb_ROM_ALU;
// Inputs
// Outputs
07
Application of ICT lab report #12
rom_alu uut (
.opCode(opCode),
.out(out)
);
initial begin
// Initialize Inputs
opCode = 0;
#100;
opCode = 1;
#100;
opCode = 2;
#100;
opCode = 3;
#100;
opCode = 2;
#100;opCode = 1;
#100;opCode = 0;
08
Application of ICT lab report #12
#100;
end
endmodule
OUTPUT:
09
Application of ICT lab report #12
TASK #03
Verilog script:
ALU:
module alu(A,B,opCode,C);
input [7:0] A, B;
case (opCode)
3'b000: C = A + B;
010
Application of ICT lab report #12
3'b001: C = A - B;
3'b010: C = A | B;
3'b011: C = A & B;
3'b100: C = A >> B;
3'b101: C = A << B;
default: C = 4'b0000;
endcase
end
endmodule
Splitter:
module splitter(instruction,opCode,A,B);
opCode = instruction[18:16];
A = instruction[15:8];
B = instruction[7:0];
end
endmodule
Calling Module:
module pc_alu(pc,C);
011
Application of ICT lab report #12
output [7:0] C;
ROM rom1(pc,instruction);
splitter split1(instruction,opCode,A,B);
alu alu1(A,B,opCode,C);
endmodule
CONCLUSION:
012