top of page
  • 8*3 Priority Encoder
  • Behavioral Modeling

module priority_encoder(v,y,d);
input [7:0]d;
output reg v;
output reg [2:0]y;
always@(d)
begin
if(d==0){v,y}=4'b1000;
else if(d>=128){v,y}=4'b0000;
else if(d>=64){v,y}=4'b0001;
else if(d>=32){v,y}=4'b0010;
else if(d>=16){v,y}=4'b0011;
else if(d>=8) {v,y}=4'b0100;
else if(d>=4){v,y}=4'b0101;
else if(d>=2){v,y}=4'b0110;
else if(d>=1){v,y}=4'b0111;

end

endmodule

  1. Using If-else
bottom of page