Lab2 and Lab3
Lab2 and Lab3
Lab2 and Lab3
LAB-2
1. Write RTL description and testbench for an Arithmetic Logic Unit using arithmetic and logical operators.
DESIGN CODE:
endcase
end
endmodule
STIMULATION CODE:
module alu_tb();
task initialise;
{a,b,command,enable}=0;
endtask
task delay();
begin
#10;
end
endtask
//Process used for generating stimulus by calling tasks & passing values
initial
begin
/*initialize;
en_oe(1'b1);
for(m=0;m<16;m=m+1)
begin
for(n=0;n<16;n=n+1)
begin
inputs(m,n);
for(o=0;o<16;o=o+1)
begin
command=o;
delay;
end
end
end */
en_oe(0);
inputs(8'd20,8'd10);
cmd(ADD);
delay;
en_oe(1);
inputs(8'd25,8'd17);
cmd(ADD);
delay;
$finish;
end
endmodule
STIMULATION WAVEFORM:
TRANSCRIPT:
SYNTHESIS CIRCUIT:
2. Write Verilog Code for verifying Operators.
DESIGN CODE:
module logical_op();
reg x,y,z,q,r,i,l,m,n,o,k;
reg [2:0]w,p;
initial
begin
a = 3'b010;
b = 3'b111;
c = 3'b00x;
d = 3'b11x;
g = 4'b10x0;
x = a && b;
y=!c;
z=!d;
w = a & c;
p = b & d;
q = & c;
r = & d;
h = g >> 1;
i= a > d;
l=a+b;
m=a-b;
n=a*b;
o=a/b;
k=a?b: c;
$display("x=%b, y=%b, z=%b, w=%b, p=%b, q=%b, r=%b, g=%b, h=%b, i=%d", x,y,z,w,p,q,r,g,h,i,l,m,n,o,k);
end
endmodule
OUTPUT:
DESIGN CODE:
always@( * )
begin
case(s)
2'b00:y=i[0];
2'b01:y=i[1];
2'b10:y=i[2];
2'b11:y=i[3]; //if not given for particular case //latchn will be inferred--not preferred for //combinational
ckts---so we have default construct default : y=1'bz;
endcase
end
endmodule
STIMULATION CODE:
module mux4x1_behavioural_tb();
reg [3:0]i;
reg [1:0]s;
wire y;
integer k;
begin
for(k=0;k<64;k=k+1)
begin
{i,s} = k;
#10;
end
end
endmodule
STIMULATION WAVEFORM:
TRANSCRIPT:
SYNTHESIS CIRCUIT:
2. Write an behavioral description for a 3:8 decoder and verify using test bench.
DESIGN CODE:
always @(*)
begin
case(a)
3'b000 : y = 8'b00000001;
3'b001 : y = 8'b00000010;
3'b010 : y = 8'b00000100;
3'b011 : y = 8'b00001000;
3'b100 : y = 8'b00010000;
3'b101 : y = 8'b00100000;
3'b110 : y = 8'b01000000;
3'b111 : y = 8'b10000000;
default : y = 8'b00000000;
endcase
end
endmodule
STIMULATION CODE:
module tb_decoder3x8_behavioural;
reg [2:0]i;
decoder3x8_behavioural DUT( i, y );
initial
begin stimulus;
end
task stimulus;
integer k;
begin i = k;
#10;
end
endtask
initial
endmodule
STIMULATION WAVEFORM:
TRANSCRIPT:
SYNTHESIS CIRCUIT:
DESIGN CODE:
always@(*)
begin
if(i[7])
begin y=3'b111;
idle=0;
end
else if(i[6])
begin y=3'b110;
idle=0;
end
else if(i[5])
begin y=3'b101;
idle=0;
end
else if(i[4])
begin y=3'b100;
idle=0;
end
else if(i[3])
begin y=3'b011;
idle=0;
end
else if(i[2])
begin y=3'b010;
idle=0;
end
else if(i[1])
begin y=3'b001;
idle=0;
end
else if(i[0])
begin y=3'b000;
idle=0;
end
else
begin y=3'b000;
idle=1;
end
end
endmodule
STIMULATION CODE:
module tb_priority_encoder8x3_behavioural;
reg [7:0]i;
wire [2:0]y;
wire idle;
initial
begin stimulus;
end
task stimulus;
integer k;
#10;
end
endtask
initial
endmodule
STIMULATION WAVEFORM:
TRANSCRIPT:
SYNTHESIS CIRCUIT: