Ode*_*ker 4 arrays comparison if-statement vhdl
我怎样才能if更好地写出这种陈述条件?
if ((data_in(8 downto 1)=x"70") or (data_in(8 downto 1)=x"69") or
(data_in(8 downto 1)=x"72") or (data_in(8 downto 1)=x"7A") or
(data_in(8 downto 1)=x"6B") or (data_in(8 downto 1)=x"73") or
(data_in(8 downto 1)=x"74") or (data_in(8 downto 1)=x"6C") or
(data_in(8 downto 1)=x"75") or (data_in(8 downto 1)=x"7D")) then
data_make_code <= data_in (8 downto 1); -- enter key to buffer
wrong_data <='0';
cnt_bit :=0;
-- if valid key then
current_state <= break_code_receive;
elsif
...
end if;
Run Code Online (Sandbox Code Playgroud)
一个case语句可以使用多个值进行比较,并且others该部分case可以被用来作为"else",如:
case data_in(8 downto 1) is
when x"70" | x"69" | x"72" | x"7A" | x"6B" |
x"73" | x"74" | x"6C" | x"75" | x"7D" =>
... -- if part of code
when others =>
... -- else part of code
end case;
Run Code Online (Sandbox Code Playgroud)
另一种方法是使用带有值的arrayof std_logic_vector,然后创建一个函数,该函数可以确定该data_in值是否等于数组中的任何一个值.该type和function然后声明可以是在architecture或process声明部分.VHDL-2008中的代码可能如下所示:
type slv_array is array (natural range <>) of std_logic_vector;
function in_array(val : std_logic_vector; set : slv_array) return boolean is
begin
for idx in set'range loop
if val = set(idx) then
return TRUE;
end if;
end loop;
return FALSE;
end function;
...
if in_array(data_in, (x"70", x"69", x"72", x"7A", x"6B",
x"73", x"74", x"6C", x"75", x"7D")) then
... -- if part of code
else
... -- else part of code
end if;
Run Code Online (Sandbox Code Playgroud)
替代方法需要一些声明,但更通用.
| 归档时间: |
|
| 查看次数: |
231 次 |
| 最近记录: |