Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The following algorithm is used to find the integer square root for an input integer number X [ Ex 1 : if X in {
The following algorithm is used to find the integer square root for an input integer number X
Ex: if X in then the result integer square root Y
Ex: if X in then the result integer square root Y
Input: X nbit integer number
Output: Y sqrtX
Step: Initialization
A X Input Data
Q
B
step: Q Q B
step: B B
repeat the last two steps step and step until Q A
step: Shift B one bit to the right a logical shift
step: Y B The result
Complete the following Verilog code to provide a behavioral implementation for this algorithm.
module SQRTCalculator
input CLK
input : X
output reg : Y
;
Your design should include the following pins:
CLK: negative edge trigger input clock
X: The input number bits Y: The result square root bitsHint: define the variables A B and Q to be of size
Notes:
if X in nn then the result integer square root Y sqrtn
Ex: if X in then the result integer square root Y
or
if X in nn then the result integer square root Y sqrtn
Ex: if X in then the result integer square root Y
Use behavioral description
DO NOT use the following operators:
DO NOT use an algorithmic state machine.
The calculation should be synchronous with the clock the result should be calculated in
a single clock cycle at the falling edge of the input clock
You have to use EDA Playground for this assignment
You have to submit two files:
A Verilog code to implement your Design.
A testbench file to simulate and test your design:
a Set the clock period to be ns
b You have to cover all the possible cases for the input data different cases
c For each case you have to:
i Select the value for X from to
ii Wait for two clock cycles
part of the solution is:
the main design:
module SQRTCalculator
input CLK
input : X
output reg : Y
;
reg : A;
reg : B;
reg : Q;
always @negedge CLK begin
A X;
Q ;
B ;
while Q A begin
Q Q B;
B B ;
end
B B ;
Y B ;
end
endmodule
the testbench is:
timescale nsps
module testbench;
reg CLK;
reg : X;
wire : Y;
integer i;
SQRTCalculator uut CLKCLKXXYY;
initial begin
CLK ;
forever # CLK ~CLK;
end
initial begin
$dumpfiledumpvcd;
$dumpvars;
for X ; X ; X X begin
#;
$displayX d Y d X Y;
end
end
endmodule
please correct any error in this code fast
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started