使用2位greater than Comparator
和2位equality Comparator
创建4位比较器时遇到了麻烦。
大于比较者
entity bit2com is
Port ( a,b: in STD_LOGIC_vector(1 downto 0);
y : out STD_LOGIC);
end bit2com;
architecture Behavioral of bit2com is
signal p0,p1,p2:std_logic;
begin
p0 <= a(1) and not b(1);
p1 <= a(0) and a(1) and not b(0);
p2<=a(0) and not b(0) and not b(1);
y <= p0 or p1 or p2;
end Behavioral;
平等比较者
entity comaeqb is
Port ( a,b: in STD_LOGIC_vector(1 downto 0);
y : out STD_LOGIC);
end comaeqb;
architecture Behavioral of comaeqb is
signal p0,p1,p2,p3:std_logic;
begin
p0 <= a(0) and a(1) and b(0) and b(1);
p1 <= a(0) and not a(1) and b(0) and not b(1);
p2<=not a(0) and not a(1) and not b(0) and not b(1);
p3<=not a(0) and a(1) and not b(0) and b(1);
y <= p0 or p1 or p2 or p3;
如何使用它比比较器大4位?
答案 0 :(得分:0)
如我所见,您尝试使用2位比较器(>
和=
)创建4位比较器。但我认为你有两个答案问题:
A and B
为signed
或unsigned
进行比较(如果您可以转换为此类型)使用std_logic_vector
)。有两个库可供使用:arith
和numeric_std
(只使用其中一个,两者都被违反)。建议A = [A3 A2 A1 A0]
和B = [B3 B2 B1 B0]
。运行两个步骤:
第1步将两个MSB与您的比较器进行比较:
if [A3 A2] > [B3 B2] then
A_greater_than_B <= '1';
elsif [A3 A2] < [B3 B2] then
A_greater_than_B <= '0';
else -- [A3 A2] = [B3 B2]
-- next step >>>
end if;
步骤2 将两个LSB与您的比较器进行比较,其方法类似于步骤1 。此分支在[A3 A2] =[ B3 B2]
时发生。 步骤2 的结果是4位比较器的结果。例如,如果[A1 A0] = [B1 B0]
则A = B
。