我需要用4:1 Mux创建XOR(我知道没有Mux就更容易......)
我发现这个有用的例子是4:1
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity multiplexer4_1 is
port (
i0 : in std_logic;
i1 : in std_logic;
i2 : in std_logic;
i3 : in std_logic;
sel : in std_logic_vector(1 downto 0);
bitout : out std_logic
);
end multiplexer4_1;
architecture Behavioral of multiplexer4_1 is
begin
process(i0,i1,i2,i3,sel)
begin
case sel is
when "00" => bitout <= i0;
when "01" => bitout <= i1;
when "10" => bitout <= i2;
when others => bitout <= i3;
end case;
end process;
end Behavioral;
但我不知道如何告诉多路复用器在输入01或10时输出1,否则为0。 我可以为i0-i3分配值吗?对不起,我是VHDL的新手
答案 0 :(得分:1)
我假设您必须使用2个输入构建XOR门。一种可能性是将两个输入分别连接到sel(0)
和sel(1)
。然后,您可以将常量值连接到剩余输入i0
到i3
,这样MUX4的真值表与XOR门的真值表相同。
答案 1 :(得分:1)
您的MUX根据选择信号将一个输入连接到输出。
如果您认为选择信号是XOR门的“输入”,您只需要确定每个XOR输入组合(选择信号)的输出应该是什么。然后连接MUX输入,以便为每个选择输入输出正确的电平。
VHDL的语法只是
inst: entity work.multiplexer4_1
port map
(
i0 => '1'; -- or '0'
etc..
sel => xor_input_signals;
bitout => xor_output_signal
);
答案 2 :(得分:1)
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity xor4_1 is
port (
--i0 : in std_logic;
--i1 : in std_logic;
--i2 : in std_logic;
--i3 : in std_logic;
sel : in std_logic_vector(1 downto 0);
bitout : out std_logic
);
end xor4_1;
architecture Behavioral of xor4_1 is
signal i0 : std_logic;
signal i1 : std_logic;
signal i2 : std_logic;
signal i3 : std_logic;
begin
process(i0,i1,i2,i3,sel)
begin
case sel is
when "00" => bitout <= i0;
when "01" => bitout <= i1;
when "10" => bitout <= i2;
when others => bitout <= i3;
end case;
end process;
-- Now just hardcode the input bits to the appropriate values.
-- I might be mistaken, but I'm pretty sure this is how the implementation tool
--s actually would implement an XOR gates.
i0 <= '0';
i1 <= '1';
i2 <= '1';
i3 <= '0';
end Behavioral;