EE3755            Verilog Homework 3  Due: TBA 
///

Estimated time to finish:

 

Prob.1 : 50Mins.

Prob.2 : 10Min.

Prob.3:  30Min.

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;
 
 
 
          
            module pop_with_handshaking(p,ready,a,start,clk);
 
   input [31:0] a;
 
   input        start, clk;
 
   output       p, ready;
   reg [5:0]    p;
   reg          ready;
   reg [31:0]   acopy;
 
   initial ready = 1;
   always @( posedge clk )
     begin
        if( start )
          begin
             acopy = a;
             p = 0;
             ready = 0;
          end
        else if( !ready && acopy )
 
          begin
 
             p = p + acopy[0];
 
             acopy = acopy >> 1;
 
          end
 
        else if( !ready && !acopy )
 
          begin
 
             ready = 1;//output is ready,also means the module is
 
                      // ready to accept new input.
 
          end
 
     end
 
 
 
endmodule
 
// Solution...Modify this or Rewrite . 
// Test bench or Stimulus Block
// (This is  not working)
// Giving this to help you.
module stimulus;
 
reg clk;
// some declarations are wrong.//reg or wire..  
reg reset;
integer i;
wire [3:0] q;
wire [5:0] p1;
reg ready,start; 
reg [31:0] a;
 
pop_with_handshaking pp1(p1,ready,a,start,clk);
 
 
 
initial
 
            clk = 1'b0; //set clk to 0
 
always
 
            #5 clk = ~clk; // toggle clk every 5 time units
 
 
 
 
initial
 begin
    
    for(i = 0; i<16 ;i= i+1) 
     begin
       a = i[5:0];
       //should also give “start” and others.
       #500;
     end  
          
    #50000 $finish;     
   
end
 
 
// Monitor the outputs
 
initial
            $monitor($time, " input a = %b  output p = %d",a,p1);
            //may use $display(   )
 
endmodule
 
 
 
 
 
 
 

Problem 2: Convert the following numbers:

 

 

Hint (5/8) = 0.625.

        

a) Decimal  10 to 8-bit Binary:

 

b) Decimal -10     to 8-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?).