您能否告诉我是否有比仅使用 if-else 语句更好的方法在 VHDL 中编写优先级编码器?我的意思是,我有这个代码并且它可以工作,但它可以写得更短吗?Switch 是一个 std_logic_vector。
谢谢你的帮助!
shifting : PROCESS(CLK_IN, new_length_ready, switch)
VARIABLE highest_switch : INTEGER RANGE 0 TO 15 := 15;
BEGIN
-- priority encoder, changes the length of the snake track
-- ( i.e., number of leds for the snake to move )
IF switch(15) = '1' THEN
highest_switch := 15;
ELSIF switch(14) = '1' THEN
highest_switch := 14;
ELSIF switch(13) = '1' THEN
highest_switch := 13;
ELSIF switch(12) = '1' THEN
highest_switch := 12;
ELSIF switch(11) = '1' THEN
highest_switch := 11;
ELSIF switch(10) = '1' THEN
highest_switch := 10;
ELSIF switch(9) = '1' THEN
highest_switch := 9;
ELSIF switch(8) = '1' THEN
highest_switch := 8;
ELSIF switch(7) = '1' THEN
highest_switch := 7;
ELSIF switch(6) = '1' THEN
highest_switch := 6;
ELSIF switch(5) = '1' THEN
highest_switch := 5;
ELSIF switch(4) = '1' THEN
highest_switch := 4;
ELSIF switch(3) = '1' THEN
highest_switch := 3;
ELSIF switch(2) = '1' THEN
highest_switch := 2;
ELSIF switch(1) = '1' THEN
highest_switch := 1;
ELSIF switch(0) = '1' THEN
highest_switch := 0;
ELSE
highest_switch := 15;
END IF