Saturday 4 February 2012

Verilog code for encoder using ASSIGN

module pri_encoder_using_assign (
  8 binary_out , //  4 bit binary output
  9 encoder_in , //  16-bit input 
 10 enable       //  Enable for the encoder
 11 );
 12 
 13 output [3:0] binary_out ;
 14 input  enable ; 
 15 input [15:0] encoder_in ; 
 16 
 17 wire [3:0] binary_out ;
 18       
 19 assign  binary_out  = ( ! enable) ? 0 : (
 20     (encoder_in[0]) ? 0 : 
 21     (encoder_in[1]) ? 1 : 
 22     (encoder_in[2]) ? 2 : 
 23     (encoder_in[3]) ? 3 : 
 24     (encoder_in[4]) ? 4 : 
 25     (encoder_in[5]) ? 5 : 
 26     (encoder_in[6]) ? 6 : 
 27     (encoder_in[7]) ? 7 : 
 28     (encoder_in[8]) ? 8 : 
 29     (encoder_in[9]) ? 9 : 
 30     (encoder_in[10]) ? 10 : 
 31     (encoder_in[11]) ? 11 : 
 32     (encoder_in[12]) ? 12 : 
 33     (encoder_in[13]) ? 13 : 
 34     (encoder_in[14]) ? 14 : 15); 
 35 
 36 endmodule 

No comments:

Post a Comment