EE3755    HW 4                 Due date : Dec 3  at the class room

                                                              We will give the solution.

Problem 1: The following module my_loop is not working.

module my_loop(a,b);

input [15:0] b;

output a;

reg [3:0] a;

reg [3:0] i;

integer s;

initial begin

s = 0;

for(i=0; i<16; i=i+1) s = s + b[i];

a = s;

end

endmodule

//

The above module is not working.

The correct code is:

reg [3:0] a;   =>                reg[4:0]  a;

reg [3:0] i;   =>  reg[4:0]  i;  

a)      why the size of “ a “should be more than 4?

b)      Why the size of  I ”  “should be more than 4?

 

Problem 2: Draw figure for  the module below.

//For those who got 0 deduction at the test, it does not mean your solution is the right one)

// your solution was close one

module adder(sum,a);

   input [7:0] a;

   output [10:0] sum;

   reg [10:0]    sum;

   integer       i;

   always @( a ) begin

      sum = 0;

      for(i=0; i<4; i=i+1) if( i <= a ) sum = sum + i;

   end

endmodule

 

(check your solution with Buildgates synthesizer program)

 

Problem 3:

 a) Write MIPS code for the below c program.

                  (Test your  code with MIPS simulator.)

 

int print_num(char *c,int n){

     int i;

                 int j;

                 for(i=0;i <n;++i){

                                 j = c[i] -'a';

                                 if(c[i] != 0) printf("%d\n",j);

                 }

     return 1;

}

 

             b) Write MIPS code for the drive program for the above code…

                 HINT: for c.

                          //  v =”abcd\0”;

                         // print_num( v,5);