Lab1 2
Lab1 2
full adder :-
module fulladd(
input a,
input b,
input cin,
output sum,
output cout
);
assign sum=(a^b^cin);
assign cout=((a&b)|(b&cin)|(a&cin));
endmodule
module lab2_152_153(
input [7:0] a,
input [7:0] b,
input cin,
output [7:0] sum,
output cout,
output [4:0] flag
);
wire [6:0] c;
fulladd a1(a[0],b[0],cin,sum[0],c[0]);
fulladd a2(a[1],b[1],c[0],sum[1],c[1]);
fulladd a3(a[2],b[2],c[1],sum[2],c[2]);
fulladd a4(a[3],b[3],c[2],sum[3],c[3]);
fulladd a5(a[4],b[4],c[3],sum[4],c[4]);
fulladd a6(a[5],b[5],c[4],sum[5],c[5]);
fulladd a7(a[6],b[6],c[5],sum[6],c[6]);
fulladd a8(a[7],b[7],c[6],sum[7],cout);
endmodule
test bench :-
module lab2_152_153_test;
// Inputs
reg [7:0] a;
reg [7:0] b;
reg cin;
wire cout;
initial begin
#10 a=8'b00000001;b=8'b00000001;cin=1'b0;
#10 a=8'b00000001;b=8'b00000001;cin=1'b1;
#10 a=8'b00000010;b=8'b00000011;cin=1'b0;
#10 a=8'b10000001;b=8'b10000001;cin=1'b0;
#10 a=8'b00011001;b=8'b00110001;cin=1'b0;
#10 a=8'b00000011;b=8'b00000011;cin=1'b1;
#10 a=8'b11111111;b=8'b00000001;cin=1'b0;
#10 a=8'b11111111;b=8'b00000000;cin=1'b1;
#10 a=8'b11111111;b=8'b11111111;cin=1'b0;
#10 $stop;
end
endmodule
--> Lab2__2 : -
Question 2(1) :-
encoded output :-
module Q2(
input [7:0] a,
output [8:0] cout
);
assign cout[1]=a[0];
assign cout[2]=a[1];
assign cout[3]=a[2];
assign cout[4]=a[3];
assign cout[5]=a[4];
assign cout[6]=a[5];
assign cout[7]=a[6];
assign cout[8]=a[7];
assign cout[0]=a[0]^a[1]^a[2]^a[3]^a[4]^a[5]^a[6]^a[7];
endmodule
test bench :-
module Q2_test;
// Inputs
reg [7:0] a;
// Outputs
wire [8:0] cout;
initial begin
// Initialize Inputs
a = 8'b11111111;
end
endmodule
Graph :-
18
Questio :- 2(2)
Error code :-
module Q2_2(
input [8:0] a,
output error
);
endmodule
test bench :-
module Q2_2_test;
// Inputs
reg [8:0] a;
// Outputs
wire error;
initial begin
// Initialize Inputs
a = 9'b111111111;
end
endmodule
--> Lab1: -
module lab6_1(
input [0:0] v1,
input [0:0] v2,
input [0:0] v3,
input [0:0] v4,
input [0:0] v5,
input [0:0] v6,
output [0:0] out
);
wire w1,w2,w3;
and g1(w1,v1,v2),g2(w2,v3,v4),g3(w3,v5,v6);
or g4(out,w1,w2,w3);
endmodule
`timescale 1ns / 1ps
module LAB6_1_2(
input [0:0] v1,
input [0:0] v2,
input [0:0] v3,
output [0:0] out
);
assign out=(v1&v2)|(v2&v3)|(v1&v3);
endmodule
module Lab6_1_3(
input [0:0] v1,
input [0:0] v2,
input [0:0] v3,
input [0:0] v4,
input [0:0] v5,
input [0:0] v6,
output reg out
);
always@(v1,v2,v3,v4,v5,v6)
if ((v1&&v2)||(v3&&v4)||(v5&&v6))
out=1;
else
out=0;
endmodule
module lab6_2_1_S(
input v1,
input v2,
input v3,
output out
);
wire x;
wire y=1'b1;
LAB6_1_2 g1(v1,v2,v3,x);
nand n1(out,x,y);
endmodule
module lab6_que3(
input [0:0] a,
input [0:0] b,
output [0:0] out
);
wire a1,a2,a3,a4;
assign #0.03 a1=~a;
assign #0.03 a2=~b;
assign #1 a3=a&a2;
assign #1 a4=b&a1;
assign #1.5 out=a3|a4;
endmodule
module Lab6_que4(
input a,
input b,
input c,
input d,
output out
);
assign out = (~(a & b) | (c & d)) ^ ((a & b) | ~(c & d));
endmodule
module lab6_qu4s(
input a,
input b,
input c,
input d,
output y
);
wire x1,x2,x3,x4,x5,x6;
and a1(x1,a,b),a2(x2,c,d);
not n1(x3,x1),n2(x4,x2);
or o1(x5,x4,x1),o(x6,x3,x2);
xor y1(y,x5,x6);
endmodule