【正文】
isComponent xor3 isPort(x,y,z::in bit。 Y:out bit)。End ponent。BeginG1:xor3 port map(a,b,c,q)。End stuct。請寫出實(shí)體相應(yīng)的關(guān)鍵詞及基本格式,并說明實(shí)體部分的功能是什么? 2. LIBRARY ieee。USE 。USE 。ENTITY mux4 IS port(s1,s2:in std_logic。 a,b,c,d:in std_logic。 muxout:out std_logic)。END ENTITY mux4。ARCHITECTURE rtl OF mux4 ISBEGIN 錯(cuò),應(yīng)該添加:process(a,b,c,d,s1,s2)case s1amp。s2 is when 00= muxout=a。 when 01= muxout=b。 when 10= muxout=c。 when “11”= muxout=d。 錯(cuò),應(yīng)該添加:when others =null。 end case。 錯(cuò),應(yīng)該添加:end process END ARCHITECTURE rtl。錯(cuò)。1)Case語句是順序語句,必須放在進(jìn)程或子程序中,在程序的結(jié)構(gòu)體里將case語句放在process語句中,如:process(a,b,c,d,s1,s2),在case完后要加end process; 2)另外,a,b,c,d定義的是std_loigc類型,所以case語句的最后一個(gè)when后要加上when others = 四、 判別下列程序的對錯(cuò),并改正有錯(cuò)的程序1. LIBRARY ieee。USE 。USE 。ENTITY forloop IS port(a:in std_logic_vector(7 downto 0)。 y:out std_logic)。END ENTITY forloop。ARCHITECTURE rtl_loop OF forloop ISBEGIN process(a) variable temp: std_logic。 begin temp=1。 錯(cuò),應(yīng)該改為:temp:=1。 for i in 0 to 7 loop temp=temp xor a(i)。 錯(cuò),應(yīng)該改為:temp:=1。 endloop。 y:=temp。end process。 END rtl。錯(cuò)。Temp為變量,變量賦值要用“:=”,而不是“=”。五、 編程題:編寫程序,完成下面的程序并給出仿真圖設(shè)計(jì)一數(shù)據(jù)選擇器MUX,其系統(tǒng)模塊圖和功能表如下圖所示?,F(xiàn)已給出實(shí)體聲明部分,試采用下面2種編程語句方式來描述該數(shù)據(jù)選擇器MUX的結(jié)構(gòu)體?!?a)用if語句、 b)case 語句 語句編程。Library ieee。Use 。Entity mymux is Port ( sel : in std_logic_vector(1 downto 0)。 選擇信號輸入 Ain, Bin : in std_logic_vector(1 downto 0)。 數(shù)據(jù)輸入 Cout : out std_logic_vector(1 downto 0) )。End mymux。a)Architecture one of mymux isBegin Process (sel, ain, bin) Begin If sel = “00” then cout = ain and bin。 Elsif sel = “01” then cout = ain xor bin。 Elsif sel = “10” then cout = not ain。 Else cout = not bin。 End if。 End process。End one。b) 根據(jù)原理圖寫出相應(yīng)的VHDL程序Library ieee。Use 。Entity mycir is Port ( A, B, clk : in std_logic。 Qout : out std_logic)。End mycir。Architecture beh of mycir is Signal ta, tb, tc。Begin tc = ta nand tb。 Process (clk) Begin If clk’event and clk = ‘1’ then Ta = A。 Tb = B。 End if。 End process。 Process (clk, tc) Begin If clk = ‘1’ then Qout =tc。 End if。 End process。End beh。