EE3755 Verilog Homework 3 Due: TBA
Estimated time to finish:
Prob.1 : 50Mins.
Prob.2 : 10Min.
Total : 90 Mins..
When you submit the Hw., Please write down how much time did you spend for each problem.
(No penalty for spending too little or too much time. Just want to know how long you spent.)
How to submit: Hard copy during the class.
Use “script “ command to take a snap shot of your program.
After run “script “
Use “cat” command to display your program.
Use “ncverilog” to run your program.
then stop the script.
Problem 1 : Rewrite or Modify the testbench program.
The program should test the number of ones in a.
a value varies from 0 to 15.
The output format may be this following:
Time, value of a at binary, value of p.
(time = 500, a = 0000 0000 0000 0000 0000 0000 0000 0000 ,p = 0;
time = 1500, a = 0000 0000 0000 0000 0000 0000 0000 0001 ,p = 1;
input [31:0] a;
input start, clk;
output p, ready;
reg [5:0] p;
reg [31:0] acopy;
initial ready = 1;
always @( posedge clk )
if( start )
acopy = a;
p = 0;
ready = 0;
else if( !ready && acopy )
p = p + acopy;
acopy = acopy >> 1;
else if( !ready && !acopy )
ready = 1;//output is ready,also means the module is
// ready to accept new input.
// Solution...Modify this or Rewrite .
// Test bench or Stimulus Block
// (This is not working)
// Giving this to help you.
// some declarations are wrong.//reg or wire..
wire [3:0] q;
wire [5:0] p1;
reg [31:0] a;
clk = 1'b0; //set clk to 0
#5 clk = ~clk; // toggle clk every 5 time units
for(i = 0; i<16 ;i= i+1)
a = i[5:0];
//should also give “start” and others.
// Monitor the outputs
$monitor($time, " input a = %b output p = %d",a,p1);
//may use $display( )
Problem 2: Convert the following numbers:
Hint (5/8) = 0.625.
a) Decimal 10 to 8-bit Binary:
b) Decimal -bit Binary:
c) Decimal 10.625 to Binary (as many bits as needed):
d) Decimal -10.625 to IEEE 754 Single Precision (Show in hexadecimal):
Problem 3: Precision in IEEE 754.
a) you have a floating point number:0.625.
Can you represent this in IEEE 754 single precision(easy one).
b) you have a floating point number: 0.123456789012345678901234567.
b1) can you represent this in IEEE 754 single precision without losing anything?
b2) how many digits of the number can the IEEE 754 single precision represent?
(Hint: C++ setw(),setprecision()
you don’t have to know the above commands.
Is setprecision(20) useful?).