使用2位Comperator的VHDL 4位Comperator

使用2位Comperator的VHDL 4位Comperator,vhdl,Vhdl,使用2位大于比较器和2位相等比较器创建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 <=

使用2位
大于比较器和2位
相等比较器创建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;
实体bit2com为
端口(a,b:标准逻辑向量(1到0);
y:输出标准(U逻辑);
结束bit2com;
bit2com的体系结构是
信号p0、p1、p2:std_逻辑;
开始

p0如我所见,您试图从2位比较器(
=
)创建4位比较器。但我认为有两个答案可以回答你的问题:

  • 如果您只想创建没有任何比较器(独立)的4位比较器,请将
    A和B
    声明为
    signed
    unsigned
    进行比较(如果使用
    std\u logic\u vector
    ,则可以转换为这种类型)。有两个库可供使用:
    arith
    numeric\u std
    (只需使用其中一个,两个库都被违反)
  • 如果必须使用2位比较器。这样做:
  • 提议
    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;
    
    如果[A3 A2]>[B3 B2]那么
    A_大于_B>
    如果结束;
    

    步骤2使用与步骤1类似的方法将两个LSB与您的比较器进行比较。当
    [A3 A2]=[B3 B2]
    时发生此分支。步骤2的结果是4位比较器的结果。例如,如果
    [A1 A0]=[B1 B0]
    A=B

    将A、B声明为数字标准。[未]签名,然后写入
    Y B,否则为“0”