Professional Documents
Culture Documents
Lab 1
Lab 1
Lab 1
EXPERIMENT – 1
Group Members:
Title:
1. For a given group number, read the ID numbers of both the students. Assign
N = sum of the last 2 digits of ID number of the first student and n = sum of the
last 2 digits of ID number of the second student (if N or n = 0 or 1, then assign it
to 5, if there are more than 2 students in the same group, the ID number of first
2 students are to be considered).
2. For a given value of N, write down a Verilog code to find its nth power.
Given input:
ID_1 = 20211230213,
ID_2 = 20211230217
N = (1+3) = 4,
P = (1+7) = 8
output finished1,finished2,
input clk,start
);
// reg flag=1'b0;
integer Ncount,Pcount;
assign N1=(N/10)+(N%10);
assign P1=(P/10)+(P%10);
always@(posedge clk)
begin
if(start)
begin
PowerN=1;
PowerP=1;
Ncount=P1;
Pcount=N1;
end
/* if(N1|P1==0|N1|P1==1)
begin
end*/
if(Ncount != 0)
begin
PowerN=N1*PowerN;
Ncount=Ncount-1;
end
if (Pcount!= 0)
begin
PowerP=P1*PowerP;
Pcount=Pcount-1;
end
end
endmodule
Testbench for N_Power without Pipeline:
module PowerN_withoutpipeline_TB(
);
wire finished1,finished2;
reg clk,start;
PowerN_withoutpipeline uut(NPowerP,PPowerN,finished1,finished2,N,P,clk,start);
initial
begin
clk = 1'b0;
end
initial
begin
start = 1'b1;
end
initial
begin
N=13;
P=17
end
endmodule
Simulation Waveform:
RTL Schematic:
Code for N_Power with Pipeline:
module Power_N_With_pipeline(
input clk,
);
wire [7:0]J,K;
reg [63:0]
powerN1,powerN2,powerN3,powerN4,powerN5,powerN6,powerN7,powerP1,powerP2,powe
rP3;
assign J=(N/10)+(N%10);
assign K=(P/10)+(P%10);
always@(*)
begin
// Pipeline stage 1
N1 <= J;
powerN1 <= J;
// Pipeline stage 2
N2 <= N1;
// Pipeline stage 3
N3 <= N2;
// Pipeline stage 4
N4 <= N3;
// Pipeline stage 5
N5 <= N4;
// Pipeline stage 6
N6 <= N5;
// Pipeline stage 7
N7 <= N6;
// Pipeline stage 8
////////////////////////////////////////////
// Pipeline stage 1
P1 <= K;
powerP1 <= K;
// Pipeline stage 2
P2 <= P1;
// Pipeline stage 3
P3 <= P2;
// Pipeline stage 4
end
endmodule
);
reg clk;
Power_N_With_pipeline uut(powerN,powerP,clk,N,P);
initial
begin
clk = 1'b0;
//start = 1'b1;
//#16 start = 1'b0;
//#96 start = 1;
end
initial
begin
N=13;
P=17;
end
endmodule
Simulation Waveform:
RTL Schematic:
Conclusion: