这两个vhdl代码有什么区别

时间:2014-02-18 14:02:03

标签: vhdl

这两个vhdl代码有什么区别?

第一

library IEEE;
use IEEE.Std_Logic_1164.all;

entity mux4 is
port(
   in1, in2, in3, in4 : in std_logic;
   ctrl: in std_logic_vector(1 downto 0);
   sai: out std_logic
   );
end mux4;

architecture mux_bhv of mux4 is
begin
    process(in1, in2, in3, in4, ctrl)
        begin case ctrl is
            when "00" => sai <= in1;
            when "01" => sai <= in2;
            when "10" => sai <= in3;
            when "11" => sai <= in4;
            when others => null;
        end case;
    end process;
end mux_bhv;

第二

library IEEE; 
use IEEE.Std_Logic_1164.all; 

entity mux4x1 is 
    port(w, x, y, z: in std_logic_vector(7 downto 0); 
        s: in std_logic_vector(1 downto 0); 
        m: out std_logic_vector(7 downto 0) 
        ); 
end mux4x1; 

architecture circuito of mux4x1 is 
begin 
    m <= w when s = "00" else 
        x when s = "01" else 
        y when s = "10" else 
        z; 
end circuito; 

3 个答案:

答案 0 :(得分:1)

第一个项目:

library IEEE;
use IEEE.Std_Logic_1164.all;

entity mux4 is
port(
in1, in2, in3, in4 : in std_logic;
ctrl: in std_logic_vector(1 downto 0);
sai: out std_logic
);
end mux4;

architecture mux_bhv of mux4 is
begin
process(in1, in2, in3, in4, ctrl)
    begin case ctrl is
        when "00" => sai <= in1;
        when "01" => sai <= in2;
        when "10" => sai <= in3;
        when "11" => sai <= in4;
        when others => null;
    end case;
end process;
end mux_bhv;

您有四个二进制一位输入,一个两位选择线和一个输出。那么,这是你的港口宣言。然后在您的架构: 案件的使用是为了选择。因此,如您输入中声明的那样,选择行是ctrl。当它为00时,选择第一个输入。如果选择ctrl“01”,则传递第二个输入,依此类推..

library IEEE; 
use IEEE.Std_Logic_1164.all; 

entity mux4x1 is 
port(w, x, y, z: in std_logic_vector(7 downto 0); 
    s: in std_logic_vector(1 downto 0); 
    m: out std_logic_vector(7 downto 0) 
    ); 
end mux4x1; 

architecture circuito of mux4x1 is 
begin 
m <= w when s = "00" else 
    x when s = "01" else 
    y when s = "10" else 
    z; 
end circuito; 

同样的想法4-1 multiplixer,但这里你的输入和输出是7位而不是只有一位。我希望你能得到它^ _ ^。

答案 1 :(得分:0)

除了std_logic vs std_logic_vector之外还有另外一个细微的区别:当m为“11”时,第二个多路复用的输出z设置为s “当s包含任何非零/一个值(即Z,X,H,L,......)时。

在第一个多路复用器中,当sai包含非零/一个值时,输出ctrl不会更新。

同样,这只是一个模拟差异。

答案 2 :(得分:0)

如上所述“在第一个多路复用器中,当sai包含非零/一个值时,输出ctrl不会更新。”
由于缺乏任务,大多数软件工具都会创建一个中间(可能是不需要的)锁存器。第二个代码中没有发生的事情,其中​​分配了所有可能的值。