Question

please explain

Question 3 1. Write behavioral Verilog code to calculate the factorial of a 3-bit unsigned number. (10 points)

2. Implement the following function using two 3-input-output lookup tables: f = abe + acid. (10 points)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The code wil be
module factor (N, z);
input [2:0] N;
output [15:0] z;
reg [15:0] z;
integer i;
always @ (N)
begin
z = 1;
i = 0;
for(i=1;i<=N;i = i + 1)

Z = i* z;
end
endmodule
module test;
wire (15:0]z;
reg (2:0]N;
factor f(N,z);
initial
$monitor("fact (%d) = %d",N,z);
initial
begin
#0 N=7;
#5 N=6;
#5 N=5;
#5 N=4;
#5 N=3;
#5 N=2;
#5 N=1:

end
endmodule

The output

C:\Users\HP.YO\Desktop>iverilog new1.vi C:\Users\HP.YO\Desktop>vvp a.out, fact (7) = 5040 fact (6) = 720 fact (5) = 120 fact

Add a comment
Know the answer?
Add Answer to:
please explain Question 3 1. Write behavioral Verilog code to calculate the factorial of a 3-bit...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT