我在做类似的事情时遇到了麻烦
b(0 to 7) <= a(7 downto 0)
Run Code Online (Sandbox Code Playgroud)
当我用ghdl编译它时,我有一个订单错误.我发现使电路工作的唯一方法如下:
library ieee;
use ieee.std_logic_1164.all;
entity reverser is
port(
a: in std_logic_vector(7 downto 0);
y: out std_logic_vector(7 downto 0);
rev: in std_logic
);
end reverser;
architecture rtl of reverser is
signal b: std_logic_vector (7 downto 0);
begin
b(7) <= a(0);
b(6) <= a(1);
b(5) <= a(2);
b(4) <= a(3);
b(3) <= a(4);
b(2) <= a(5);
b(1) <= a(6);
b(0) <= a(7);
y <= b when rev = '1' else a;
end rtl;
Run Code Online (Sandbox Code Playgroud)
建议?提前致谢
Mar*_*son 24
这是不允许的 - VHDL是如此强大的类型,如果你想要反转位顺序,你必须明确地做.
标准解决方案是使用一个函数(我没有写这个 - 乔纳森布罗姆利做了):
function reverse_any_vector (a: in std_logic_vector)
return std_logic_vector is
variable result: std_logic_vector(a'RANGE);
alias aa: std_logic_vector(a'REVERSE_RANGE) is a;
begin
for i in aa'RANGE loop
result(i) := aa(i);
end loop;
return result;
end; -- function reverse_any_vector
Run Code Online (Sandbox Code Playgroud)
小智 5
这个问题有几种解决方案。一种可能性如下:
gen: for i in 0 to 7 generate
y(i) <= a(i) when rev='0' else a(7-i);
end generate;
Run Code Online (Sandbox Code Playgroud)