【正文】
r(4 downto 0)。signal p: std_logic_vector(3 downto 0)。signal g: std_logic_vector(3 downto 0)。begin G1:for i in 0 to 3 generate p(i)=a(i) xor b(i)。 g(i)=a(i) and b(i)。 s(i)=p(i) xor c(i)。end generate。c(0)=cin。c(1)=(cin and p(0)) or g(0)。c(2)=(cin and p(0) and P(1)) or (g(0) and p(1)) or g(1)。c(3)=(cin and p(0) and P(1)and P(2)) or (g(0) and p(1) and P(2)) or (g(1) and P(2)) or g(2)。c(4)=(cin and p(0) and P(1)and P(2) and P(3)) or (g(0) and p(1) and P(2) and P(3)) or (g(1) and P(2) and P(3)) or (g(2) and P(3)) or g(3)。cout=c(4)。end behav。8位加法器:library ieee。use 。entity adder is port(a,b:in std_logic_vector(7 downto 0)。 s:out std_logic_vector(7 downto 0)。 cin:in std_logic。 cout:out std_logic)。end adder。architecture behav of adder isponent adder4 is port(a,b:in std_logic_vector(3 downto 0)。 s:out std_logic_vector(3 downto 0)。 cin:in std_logic。 cout:out std_logic)。end ponent。signal m1,m2,m3:std_logic。begin u1:adder4 port map(a(3 downto 0),b(3 downto 0),s(3 downto 0),cin,m1)。 u2:adder4 port map(a(7 downto 4),b(7 downto 4),s(7 downto 4),m1,cout)。 end behav。選擇運(yùn)算器用到的元件聲明:library ieee。use 。package my_ponents_1 is ponent multiplier is port(a,b:in std_logic_vector (7 downto 0)。 prod:out std_logic_vector(15 downto 0))。 end ponent。 ponent adder is port(a,b:in std_logic_vector(7 downto 0)。 s:out std_logic_vector(7 downto 0)。 cin:in std_logic。 cout:out std_logic)。 end ponent。end my_ponents_1。選擇運(yùn)算器:library ieee。use 。use 。entity operation is port(a,b: in std_logic_vector(7 downto 0)。 cout: out std_logic_vector(15 downto 0))。end operation。architecture behav of operation is signal w1:std_logic_vector(15 downto 0)。 signal w2:std_logic_vector(7 downto 0)。 signal w3:std_logic 。 signal flag:integer range 1 to 3 :=3。begin u1:ponent multiplier port map(a,b,w1)。 u2:ponent adder port map(a,b,w2,39。039。,w3)。 process(a,b) begin if(ab)then flag=1。 elsif(ab)then flag=2。 else flag=3。 end if。 end process。 with flag select cout= w1 when 1, 0000000amp。 w3 amp。 w2 when 2, (others=39。039。)when others。end behav。測(cè)試文件:library ieee。use 。entity operation_tb isend operation_tb。architecture behav of operation_tb is ponent operation port(a,b:in std_logic_vector(7 downto 0)。 cout:out std_logic_vector(15 downto 0))。end ponent。signal a,b:std_logic_vector(7 downto 0)。signal cout:std_logic_vector(15 downto 0)。begin w:operation port map(a=a,b=b,cout=cout)。 input_gen:process begin a=01111111。 b=00000001。 wait for 100 ns。 a=00001111。 b=01000001。 wait for 100 ns。 a=10101010。 b=10101010。 wait for 100 ns。 a=11100100。 b=10101010。 wait for 100 ns。 a=00101010。 b=10101010。 wait for 100 ns。 a=11101111。 b=11101111。 wait for 100 ns。 wait。 end process。end 。四、仿真結(jié)果五、總結(jié)與感悟 通過(guò)這4周的實(shí)驗(yàn),我對(duì)VHDL語(yǔ)言有了更加深刻的理解,同時(shí)對(duì)linux操作系統(tǒng)有了一定了解。在實(shí)踐中,我對(duì)理論知識(shí)理解薄弱的地方進(jìn)行了加強(qiáng),例如元件的聲明和例化(ponent語(yǔ)句)不屬于書(shū)面的考試范圍,我一直對(duì)其理解的不充分,但是通過(guò)后兩次的實(shí)驗(yàn),我逐漸掌握了這部分知識(shí),這充分說(shuō)明了學(xué)習(xí)VHDL語(yǔ)言時(shí),必須經(jīng)常自己動(dòng)手編程,在實(shí)踐中不斷查漏補(bǔ)缺。 很感謝桂老師和任老師的悉心教導(dǎo),讓我對(duì)這門(mén)語(yǔ)言產(chǎn)生了充分的興趣,學(xué)到了很多有用的知識(shí)。