2012年11月26日 星期一

Task & Function

Task & Function 


// an example illustrating how to count the zeros in a byte.
module zero_count_task (data, out); 
   input [7:0] data;
   output reg [3:0] out; // output declared as register
   
   always @(data)
   count_0s_in_byte(data, out);
   // task declaration from here.


    task count_0s_in_byte(input [7:0] data, 
                                          output reg [3:0] count);
    integer i;
       begin // task body
          count = 0; 
          for (i = 0; i <= 7; i = i + 1)
            // The following statement can be replaced by
           // : count = count + ~data[i]. Why?
           if (data[i] == 0) count= count + 1;
       end 
   endtask

endmodule




// an example illustrating how to count the zeros in a byte.
module zero_count_function (data, out); 
    input [7:0] data;
   output reg [3:0] out; // output declared as register

   always @(data)

   out = count_0s_in_byte(data);


   // function declaration from here.
   function [3:0] count_0s_in_byte(input [7:0] data);
       integer i; 
       begin 
           count_0s_in_byte = 0;
           for (i = 0; i <= 7; i = i + 1)

            // the following statement can be replaced by: 
            // count_0s_in_byte = count_0s_in_byte + ~data[i]. Why?

         if (data[i] == 0) 
                count_0s_in_byte = count_0s_in_byte + 1;
     end

     endfunction


endmodule




沒有留言:

張貼留言

2024_09 作業3 以Node-Red 為主

 2024_09 作業3  (以Node-Red 為主  Arduino 可能需要配合修改 ) Arduino 可能需要修改的部分 1)mqtt broker  2) 主題Topic (發行 接收) 3) WIFI ssid , password const char br...