0% found this document useful (0 votes)
5K views

Priority Encoder Verilog Code

This Verilog code sample implements a priority encoder that takes in an 8-bit input select and outputs a 3-bit code indicating the highest priority bit set in the select input. It uses a series of if-else statements to check each bit of select from lowest to highest priority and assigns the corresponding 3-bit code to the output if that bit is set.

Uploaded by

2prashant2
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5K views

Priority Encoder Verilog Code

This Verilog code sample implements a priority encoder that takes in an 8-bit input select and outputs a 3-bit code indicating the highest priority bit set in the select input. It uses a series of if-else statements to check each bit of select from lowest to highest priority and assigns the corresponding 3-bit code to the output if that bit is set.

Uploaded by

2prashant2
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Verilog code sample for priority encoder

module priority (select, code);


input [7:0] select;
output [2:0] code;
reg [2:0] code;
always @(select)
begin
if (sel[0]) code <= 3'b000;
else if (sel[1]) code <= 3'b001;
else if (sel[2]) code <= 3'b010;
else if (sel[3]) code <= 3'b011;
else if (sel[4]) code <= 3'b100;
else if (sel[5]) code <= 3'b101;
else if (sel[6]) code <= 3'b110;
else if (sel[7]) code <= 3'b111;
else code <= 3'bxxx;
end
endmodule

You might also like