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




沒有留言:

張貼留言

Messaging API作為替代方案

  LINE超好用功能要沒了!LINE Notify明年3月底終止服務,有什麼替代方案? LINE Notify將於2025年3月31日結束服務,官方建議改用Messaging API作為替代方案。 //CHANNEL_ACCESS_TOKEN = 'Messaging ...