Solution to HW3 1. a) decimal 12 00001100 b) decimal -12 11110100 c)1100.111 d)0x414e0000 2. Hello,x=1,t=0 Hello,x=2,t=0 Hello,x=3,t=0 Hello,x=1,t=0 Hello,x=2,t=1 Hello,x=3,t=2 3. module floatconversion(floatori); input floatori; real floatori; integer i,index,realindex,j,jj; reg sign; reg [7:0] exp; reg [22:0] realfrac,frac; reg zero, pos, neg; reg [5:0] loc; reg [31:0] a; real floatori,float,float1; initial begin float = floatori; sign = (float >=0)? 0:1; if(sign) float = -float; i = float; if((i - float) >0 ) i = i - 1; //find position of leading one realindex = 0; for(index = 31;index>=0;index = index-1) begin if(i[index] == 1 && realindex == 0) realindex = index; end exp = realindex + 127; float = float - i; i[0] = 0; for(index = 22;index>=0;index = index-1) begin float = float *2; i[0] = 0; if(float>=1) begin i[0] = 1; float = float -1; end frac[index] = i[0]; end j = realindex - 1; jj = 0; for(index = 22;index >=0;index = index -1) begin if(j>=0) begin realfrac[index]= i[j]; j = j- 1; end else begin realfrac[index] = frac[22-jj]; jj = jj+1; end end $display("Decimal %f convert to \n %b%b%b\n",floatori,sign,exp,realfrac); end endmodule 4. 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 module stimulus; reg clk; reg reset; integer i; wire [3:0] q; wire [5:0] p1; wire ready; reg start; reg [31:0] a; pop_with_handshaking pp1(p1,ready,a,start,clk); initial clk = 1'b0; //set clk to 0 always #1 clk = ~clk; // toggle clk every 1 time units initial begin for(i = 0; i<50 ;i= i+1) begin a = i[5:0]; start = 1; #50; start = 0; if(ready ==0) begin #50; end $display($time," input a = %b output p = %d",a,p1); end #1600 $finish; end endmodule 5. 5-1)Explicit is longer 5-2) 0 1 5-3) 1 x 5-4) 000000 001111 5-5) 0011 0001