今天看到一个程序,两个8位带符号数相加,要考虑到数据位扩展的问题,程序如下:
library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_signed.all;
entity Add2In is port( D1:in std_logic_vector(7 downto 0); D2:in std_logic_vector(7 downto 0); Q :out std_logic_vector(8 downto 0); Clk: in std_logic); end Add2In;
architecture A_Add2In of Add2In is begin process(Clk) begin if Clk = '1' and Clk'event then Q <= (D1(D1'left)&D1)+(D2(D2'left)&D2); end if; end process; end A_Add2In;
里边的Q <= (D1(D1'left)&D1)+(D2(D2'left)&D2);这句应该是数据位扩展,但我怎么也看不明白这个语句是怎么组合的,请大家指教一下,谢谢! |