【正确答案】由LS85构成的24位比较器的结构如课本图所示。采用元件例化的设计comp24程序如下。
library ieee;
use ieee. std_logic_1164.all;
entity comp24 is
port(ida,idb:in std_logic vector(23 downto 0);
ogt,ols,oeq:out std_logic);
end comp24;
architecture struc24 of comp24 is
COMPONENT ls85
port(ind1,ind2:in std_logic_vector(3 downto 0);
gi,si,ei:in std_logic;
great,less,equal:out std_logic);
END COMPONENT;
signal sx:std_logic_vector(0 to 14);
signal sza,szb:std_logic_vector(3 downto 0);
signal sy0,sy1:std_logic;
begin
sy0<='0'; sy1<='1';
cj1:ls85 port map(ida(3 downto 0),idb(3 downto 0),sy0,sy0,sy1,sx(2),sx(1),sx(0));
cj2:ls85 port map(ida(8 downto 5),idb(8 downto 5),ida(4),idb(4),sy0,sx(5),sx(4),sx(3));
cj3:ls85 port map(ida(13 downto 10),idb(13 downto 10),ida(9),idb(9),sy0,sx(8),sx(7),sx(6));
cj4:ls85 port map(ida(18 downto 15),idb(18 downto 15),ida(14),idb(14),sy0,sx(11),sx(10),sx(9));
cj5:ls85 port map(ida(23 downto 20),idb(23 downto 20),ida(19),idb(19),sy0,sx(14),sx(13),sx(12));
cj6:ls85 port map(sza,szb,gi=>sx(2),si=>sx(1),ei=>sx(0),great =>ogt,
less =>ols,equal =>oeq);
sza<= sx(14)&sx(ll)&sx(8)&sx(5);szb<= sx(12)&sx(9)&sx(6)&sx(3);
end architecture struc24;
本题的目的是练习元件例化语句的应用。如果目的仅是比较两个24位数的大小,完全可以用行为描述的方式解决。将两个数ind1,ind2的位宽定为24即可。
【答案解析】