lec3 VHDL第三次作業(yè)

chapter 10

10.16. 二進(jìn)制加法送漠。實(shí)現(xiàn)兩個(gè)十六進(jìn)制數(shù)相加 2A + 3C

2A + 3C == 66Hex = 102Dec

10.18. 位計(jì)數(shù)電路软驰。用全加器設(shè)計(jì)一個(gè)電路二拐,接受一個(gè)7位輸入能犯,輸出一個(gè)表示輸入中1的個(gè)數(shù)的3位二進(jìn)制數(shù)愤兵。

設(shè)計(jì)思路:從輸入的低位開始掃描序列赐俗,設(shè)計(jì)的全加器為3位,將輸入的每一位的高2位補(bǔ)0,并與上一次輸入的結(jié)果一同輸入到一個(gè)新的全加器中握牧,若該位為1則結(jié)果加1容诬,若該位為0則結(jié)果不變,這樣最終累加的結(jié)果將保存再ypp(6)中沿腰,ypp是一個(gè)二維數(shù)組览徒。

仿真結(jié)果圖所示,當(dāng)輸入為9時(shí)颂龙,即 0001001习蓬,其中1的個(gè)數(shù)為2,輸出結(jié)果y也為2措嵌,符合設(shè)計(jì)要求躲叼,其他的輸入也同樣符合要求,可知設(shè)計(jì)正確企巢。

10-18-465464658

代碼如下所示枫慷。其中FA是加法器,count1是技術(shù)電路浪规,count_test是計(jì)數(shù)電路或听。

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity FA is
    generic(n: integer := 8);
    port (
        a,b: in std_logic_vector(n-1 downto 0);
        cin: in std_logic;
        cout: out std_logic;
        s:out std_logic_vector(n -1 downto 0)

    ) ;
end FA;

architecture impl of FA is

    signal sum: std_logic_vector(n downto 0);

begin
    sum <= ('0' & a) + ('0' & b) + cin;
    cout <= sum(n);
    s <= sum(n-1 downto 0);
end impl ; -- impl


library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity count1 is
  port (
    a: in std_logic_vector(6 downto 0);
    y: out std_logic_vector(2 downto 0)
  ) ;
end count1;

architecture impl of count1 is
    type PartialP is array(6 downto 0) of std_logic_vector ( 2 downto 0);
    signal ypp : PartialP;
    signal cout: std_logic;
    signal xin: PartialP;

begin
    xin(0) <= "00" & a(0);
    d0: entity work.FA generic map(3) port map(xin(0), "000", '0',cout, ypp(0));
    xin(1) <= "00" & a(1);
    d1: entity work.FA generic map(3) port map(xin(1), ypp(0), '0',cout, ypp(1));
    xin(2) <= "00" & a(2);
    d2: entity work.FA generic map(3) port map(xin(2), ypp(1), '0',cout, ypp(2));
    xin(3) <= "00" & a(3);
    d3: entity work.FA generic map(3) port map(xin(3), ypp(2), '0',cout, ypp(3));
    xin(4) <= "00" & a(4);
    d4: entity work.FA generic map(3) port map(xin(4), ypp(3), '0',cout, ypp(4));
    xin(5) <= "00" & a(5);
    d5: entity work.FA generic map(3) port map(xin(5), ypp(4), '0',cout, ypp(5));
    xin(6) <= "00" & a(6);
    d6: entity work.FA generic map(3) port map(xin(6), ypp(5), '0',cout, ypp(6));
    y <= ypp(6);
end impl ; -- impl


--pragma translate_off

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.numeric_std.all;


entity count_test is
end count_test;

architecture impl of count_test is
    signal a: std_logic_vector(6 downto 0);
    signal y: std_logic_vector(2 downto 0);
    
    begin

        p1: entity work.count1 port map(a, y);
        process begin
          for i in 0 to 2**7 - 1 loop
              a <= std_logic_vector(to_unsigned(i, 7));
              wait for 10 ns;
          end loop;
        end process;

end impl ; -- test
--pragma translate_on

10.20. 飽和加法器設(shè)計(jì)。在一些應(yīng)用中笋婿,特別是信號處理中誉裆,希望加法器飽和,再溢出狀態(tài)下產(chǎn)生2n-1 的結(jié)果缸濒,而不是模運(yùn)算后的結(jié)果足丢。設(shè)計(jì)一個(gè)飽和加法器,可以使用n位加法器和n位多路復(fù)用器作為基本器件

飽和加法器庇配,當(dāng)正向溢出的時(shí)候輸出輸出最大正數(shù)霎桅,當(dāng)負(fù)向溢出的時(shí)候輸出最小負(fù)數(shù)。分析可知讨永,當(dāng)符號位進(jìn)位為’1‘滔驶,數(shù)據(jù)最高位進(jìn)位為‘0‘時(shí)發(fā)生負(fù)向溢出,即兩個(gè)負(fù)數(shù)相加超出最小負(fù)數(shù)表示范圍卿闹,當(dāng)符號進(jìn)位為’0‘且數(shù)據(jù)最高位進(jìn)位為’1‘時(shí)揭糕,發(fā)生正向溢出,即兩個(gè)正數(shù)相加超過最大正數(shù)表示范圍锻霎。

因此可以改造全加器著角,當(dāng)發(fā)生正向溢出時(shí)符號位設(shè)置為’0‘,數(shù)據(jù)位全設(shè)置為‘1’旋恼,表示最大正數(shù)吏口;當(dāng)發(fā)生負(fù)向溢出時(shí),符號位設(shè)置為‘1’,數(shù)據(jù)位全設(shè)置為‘0’表示最小負(fù)數(shù)

仿真結(jié)果如下所示产徊,設(shè)計(jì)的前20ns位兩組特殊的數(shù)據(jù)昂勒,前10ns為 1000 + 1010 發(fā)生負(fù)向溢出,應(yīng)該輸出1000舟铜,仿真結(jié)果符合預(yù)期戈盈,10-20ns輸入為0111+ 0010,為正向溢出谆刨,輸出結(jié)果為0111塘娶,符合預(yù)期,之后輸入a從0010開始每隔40ns加1痊夭,輸入b從0001開始每隔10ns加1刁岸,通過觀察發(fā)現(xiàn),輸出的結(jié)果也是符合預(yù)期她我,說明設(shè)計(jì)正確虹曙。

10-20

代碼如下所示

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity fulladd is
    generic(N: integer := 8);
    port (
        a,b: in std_logic_vector(n-1 downto 0);
        sub: in std_logic;
        s: out std_logic_vector(n-1 downto 0);
        ovf: out std_logic
    ) ;
end fulladd;

architecture impl of fulladd is

    signal c1, c2: std_logic;
    signal c1n: std_logic_vector(n-1 downto 0);
    signal c2s: std_logic_vector(1 downto 0);

begin
    ovf <= c1 xor c2;
    c1n <= ('0' & a(n-2 downto 0)) + ('0' & (b(n -2 downto 0) xor (n-2 downto 0 => sub))) + sub;
    -- s(n-2 downto 0) <= c1n(n-2 downto 0);
    c1 <= c1n(n - 1);
    c2s <= ('0' & a(n-1)) + ('0' & (b(n - 1) xor sub)) + c1;
    -- s(n - 1) <= c2s(0);
    c2 <= c2s(1);
    s(n - 2 downto 0) <= (n-2 downto 0 => '1') when c1 = '1' and c2 = '0'  
    else (n-2 downto 0 => '0') when c2 = '1' and c1 = '0'
    else c1n(n -2 downto 0);

    s(n - 1) <= '0' when c1 = '1' and c2 = '0' 
    else '1' when c2 = '1' and c1 = '0'
    else c2s(0);
end impl ; -- impl


--pragma translate_off

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.numeric_std.all;


entity fulladd_test is
end fulladd_test;

architecture impl of fulladd_test is
    signal a: std_logic_vector(3 downto 0);
    signal b: std_logic_vector(3 downto 0);
    signal y: std_logic_vector(3 downto 0);
    signal ovf: std_logic;
    
    begin

        p1: entity work.fulladd generic map(4) port map(a, b, '0', y, ovf);
        process begin
            a <= "1000";
            b <= "1010";
            wait for 10 ns;
            a <= "0111";
            b <= "0010";
            wait for 10 ns;
            for i in 2 to 2**4 -1 loop
                a <= std_logic_vector(to_unsigned(i, 4));
                for j in 1 to 2**4 -1 loop
                    b <= std_logic_vector(to_unsigned(j, 4));
                    wait for 10 ns;
                end loop;
            end loop;
        end process;

end impl ; -- test
--pragma translate_on

10.44. 倍5電路。使用加法器鸦难,組合構(gòu)建塊和門,設(shè)計(jì)一個(gè)接收4位基2補(bǔ)碼二進(jìn)制輸入a(3 downto 0)的電路员淫,并輸入一個(gè)7位基2補(bǔ)碼輸出b(6 downto 0)合蔽,輸出是輸入的5倍。不能使用乘法器介返,使用盡可能少的加法器拴事。

設(shè)計(jì)思路:將輸入左移兩位,得到原輸入的四倍圣蝎,在使用一個(gè)加法器加上原來輸入元素刃宵,得到原輸入的五倍,需要注意的是徘公,輸入的是基2的補(bǔ)碼牲证,最高位表示符號位,在左移兩位后需要對原數(shù)據(jù)進(jìn)行符號擴(kuò)展关面。

如下所示坦袍,當(dāng)輸入由0000-0111時(shí),輸入為正數(shù)等太,輸出直接擴(kuò)大五倍捂齐,當(dāng)輸入為1000時(shí),表示的時(shí)-8缩抡,輸出為58Hex 轉(zhuǎn)換為十進(jìn)制的數(shù)為-40奠宜,符合題意,同理驗(yàn)證其他復(fù)數(shù)也符合5倍的要求,可知電路設(shè)計(jì)正確压真。

10-44

設(shè)計(jì)代碼如下所示

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity addsub is
    generic(N: integer := 8);
    port (
        a,b: in std_logic_vector(n-1 downto 0);
        sub: in std_logic;
        s: out std_logic_vector(n-1 downto 0);
        ovf: out std_logic
    ) ;
end addsub;

architecture impl of addsub is

    signal c1, c2: std_logic;
    signal c1n: std_logic_vector(n-1 downto 0);
    signal c2s: std_logic_vector(1 downto 0);

begin
    ovf <= c1 xor c2;
    c1n <= ('0' & a(n-2 downto 0)) + ('0' & (b(n -2 downto 0) xor (n-2 downto 0 => sub))) + sub;
    s(n-2 downto 0) <= c1n(n-2 downto 0);
    c1 <= c1n(n - 1);
    c2s <= ('0' & a(n-1)) + ('0' & (b(n - 1) xor sub)) + c1;
    s(n - 1) <= c2s(0);
    c2 <= c2s(1);
end impl ; -- impl


library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity fives is
  port (
    num: in std_logic_vector(3 downto 0);
    y: out std_logic_vector(6 downto 0)
  ) ;
end fives;

architecture impl of fives is

    signal num_sll_2, num_temp: std_logic_vector(6 downto 0) := "0000000";
    signal ovf: std_logic;

begin
num_temp <= "111" & num when num(3) = '1' else "000" & num ;
num_sll_2(5 downto 0) <= num & "00";
num_sll_2(6) <= '1' when num(3) = '1' else '0';

e0: entity work.addsub generic map(7) port map(num_temp, num_sll_2, '0', y, ovf);
end impl ; -- impl


--pragma translate_off

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.numeric_std.all;


entity fives_test is
end fives_test;

architecture impl of fives_test is
    signal a: std_logic_vector(3 downto 0);
    signal y: std_logic_vector(6 downto 0);
    
    begin

        p1: entity work.fives  port map(a, y);
        process begin
          for i in 0 to 2**4 - 1 loop
              a <= std_logic_vector(to_unsigned(i, 4));
              wait for 10 ns;
          end loop;
        end process;

end impl ; -- test
--pragma translate_on

chapter 11

11.6. 定點(diǎn)數(shù)表示娩嚼。將0.3775轉(zhuǎn)化到最近的s1.5格式定點(diǎn)數(shù)表示,給出絕對跟相對誤差

0.3775 * 25 = 12.08 ≈ 12 = 01100

轉(zhuǎn)為s1.5的形式為0.01100 = 0.375

絕對誤差 = | 0.375 - 0.3775 | = 0.0025

相對誤差為<span>(0.3775 - 0.375) / 0.3775 = 0.0066</span>

11.11. 選擇定點(diǎn)表示方案榴都。以0.1PSI的精度表示一個(gè)范圍從-10PSI到10PSI的相對壓力信號待锈。選擇一個(gè)指定精度的并且以最少位數(shù)覆蓋此范圍的定點(diǎn)表示方法

由于2-4 < 0.1 所以小數(shù)部分可以用四位二進(jìn)制表示,由于要表示正負(fù)數(shù)嘴高,需要一位符號位竿音,整數(shù)位可以用4位二進(jìn)制數(shù)表示,因此最終表示格式位9位:s4.4

11.18. 浮點(diǎn)表示拴驮。將100 000轉(zhuǎn)化成偏移量為8春瞬,格式為s3E5的浮點(diǎn)數(shù),并給出相對誤差跟絕對誤差

s3E5從左到右為1位符號套啤,5位指數(shù)宽气,3位小數(shù),將(100,000)10 轉(zhuǎn)化為2進(jìn)制數(shù)位 1 1000 0110 1010 0000 = 1.1000011010100000 * 21 0000

由于偏移量為8潜沦,指數(shù)部分需要加上1000萄涯,最終得到指數(shù)位1 1000

要求保留三位小數(shù),可得小數(shù)部分為100

最終得到的s3E5浮點(diǎn)數(shù)為 0 11000 100唆鸡,表示為十進(jìn)制數(shù)為98,304

絕對誤差 = 100,000 - 98,304 = 1,696

相對誤差為(100,000 - 98,000) / 100,000 = 0.01696

復(fù)習(xí)題

1. 噪聲容限涝影,VOL = 0.1V, VOH = 0.9V, VIL = 0.5V, VIH = 0.7V

  • 噪聲容限的最大值和最小值是多少?

    VNMH = VOH - VIH = 0.2V

    VNML = VIL - VOL = 0.4V

  • 電源電壓(相對于GND)的允許容限如何估算争占?

    電源電壓的最小值不能小于器件允許的最小值燃逻,不能超過器件允許的最大值,同時(shí)避免在(VIL, VIH)之間

  • 假定 VIH-VIL >= 0.2V臂痕,如何調(diào)整這些伯襟?

    增大VIH 減小VIL ,但若需要保證傳輸曲線增益不變根據(jù)|dvout / dvin| >= (VOH - VOL) / (VIH - VIL)VOH - VIL也需要相應(yīng)的增大

2. 為了用數(shù)字技術(shù)處理信號握童,信號怎么表示

  • 單一信號可以如何表示姆怪?舉例說明

    單一信號可以用1bit表示,如白天跟晚上澡绩,0便是白天片效,1表示晚上

  • 集合信號可以如何表示?舉例說明

    集合信號可以用01集合進(jìn)行編碼英古,如紅綠藍(lán)紫淀衣,可以用2bit表示,00表示紅召调,01表示綠膨桥,10表示藍(lán)蛮浑,11表示紫色。

  • 討論如何表示棋盤

    • 圍棋棋盤

      可以使用位圖表示只嚣,其中每一位包括2bit信息沮稚,00表示沒有棋子,01表示有白子册舞,10表示有黑子蕴掏。

    • 中國象棋棋盤

      象棋棋盤同樣也可以用位圖表示,位圖中每一位有8bit數(shù)據(jù)调鲸,8b'0表示一個(gè)位子沒有數(shù)據(jù)盛杰,若不全為0,最高位1表示紅方藐石,0表示藍(lán)方即供,剩下的7位分別對卒車馬象帥等棋子進(jìn)行編碼

3. 化簡邏輯函數(shù)

  • f = (x & y & z) | (x & y) | (x’ & y & z)

    = (y & z & x ) | (y & z & x') | (x & y)

    = (y & z) & (x | x') | (x & y)

    = (y & z) | (y & x)

    = y & (x | z)

  • f = (x & y & z) | (x & y’) | (x & z’)

    = (x & y & z) | [x & (y & z)']

    = x & [(y & z) | (y & z)']

    = x

4. 對偶與互補(bǔ)

給定一個(gè)邏輯函數(shù) f(a,b,c),其互補(bǔ)函數(shù)寫作f’ = f’(a,b,c)于微,對偶函 數(shù)寫作fD = f’(a’,b’,c’)

  • 假定 f = AND (與運(yùn)算), 其互補(bǔ)函數(shù)是 _____?對偶函數(shù)是_____?

    互補(bǔ)函數(shù)是 OR

    對偶函數(shù)是 NOR

  • 假定 f = 3-bit 質(zhì)數(shù)函數(shù)逗嫡,f 輸入為1,2,3,5,7時(shí)輸出為1(Ture)

    f函數(shù)的真值表如下所示

c\ba 00 01 11 10
0 0 1 1 1
1 0 1 1 0

f = a | ( b & c')

  • 互補(bǔ)函數(shù)f’ 在輸入為_______時(shí)產(chǎn)生輸出“1”?

    f’ = a & ( b | c')

    1株依,3驱证,7

  • 對偶函數(shù)fD 在輸入圍_______時(shí)產(chǎn)生輸出“1”?

    fD = a‘ & ( b’ | c)

    0恋腕,4抹锄,6

5. 6. 手工組合邏輯電路設(shè)計(jì)(感覺第五第六題再說一個(gè)東西,沒太明白題意)

從設(shè)計(jì)規(guī)范入手吗坚,寫出卡諾圖祈远,找出關(guān)鍵蘊(yùn)含項(xiàng)( prime implicants )呆万, 選擇覆蓋邏輯函數(shù)的關(guān)鍵蘊(yùn)含項(xiàng)的最小集

  • 試圖設(shè)計(jì)組合邏輯電路商源,實(shí)現(xiàn)4-bit 輸入的Fibonacci 數(shù)列判斷 (給出設(shè)計(jì)過程,一種電路圖谋减,一種VHDL描述)

    • 不是設(shè)計(jì)電路產(chǎn)生Fibonacci數(shù)列

    • 是類似講義中質(zhì)數(shù)(素?cái)?shù))的判斷

    • 斐波那契數(shù)列(Fibonacci )牡彻,又稱黃金分割數(shù)列 “兔子數(shù)列”。這個(gè)序列的前幾項(xiàng)是這樣的:0,1,1,2,3,5,8,13,21,34,?在數(shù)學(xué)上出爹,斐波納契數(shù)列以如下被以遞歸的方法定義:

      • F(0)=0

      • F(1)=1

      • F(n)=F(n?1)+F(n?2) ,(n≥2,n∈N)

        4-輸入信號的Fibonacci(斐波那契數(shù)列)電路 當(dāng)輸入(dcba)為1,2,3,5,8, 及 13時(shí)庄吼,輸出為True

        1584115827
  • 補(bǔ)充其他方法,至少包含一種VHDL描述

    將每個(gè)位1的項(xiàng)或起來直接輸出

    7bac1874682a0da3086eb5294d4718f
    library ieee;
    use ieee.std_logic_1164.all;
    
    entity fib_condition is
      port (
        num : in std_logic_vector(3 downto 0);
        is_fib: out std_logic);
    end fib_condition;
    
    architecture fib_condition_impl of fib_condition is
    begin
      process( num )
      begin
        case num is
          when "0000" | "0001" | "0010" | "0011" | "0101" | "1000" | "1101"
           => is_fib <= '1';
          when others => is_fib <= '0';
        end case;
      end process ;
    end fib_condition_impl;
    

7. 寫出 該電路行為的一種 VHDL描述

5d8e4ed2974e38bdf10248a3fa89f4a
library ieee;
use ieee.std_logic_1164.all;

entity fib_condition is
  port (
    num : in std_logic_vector(3 downto 0);
    is_fib: out std_logic);
end fib_condition;

architecture fib_condition_impl of fib_condition is
begin
  process( num )
  begin
    case num is
      when "0000" | "0001" | "0010" | "0011" | "0101" | "1000" | "1101"
       => is_fib <= '1';
      when others => is_fib <= '0';
    end case;
  end process ;
end fib_condition_impl;

8. 寫出 該電路行為的一種 VHDL描述

1584117550
library ieee;
use ieee.std_logic_1164.all;

entity test is
  port (
    num : in std_logic_vector(3 downto 0);
    is_fib: out std_logic);
end fib_condition;

architecture fib_condition_impl of test is
begin
  process( num )
  begin
    case num is
      when "0111" | "1100" | "1101" | "1111" | "1110" | "1011" => is_fib <= '1';
      when others => is_fib <= '0';
    end case;
  end process ;
end fib_condition_impl;

9. 組合邏輯電路模塊(單元)的利用

  • 提高抽象層次严就,使用組件(組合邏輯單元)而不是直接使用卡諾圖設(shè)計(jì)電路

    • 假定組合邏輯電路來自預(yù)定義的電路單元
    • 編碼器Encoder – 將one-hot信號轉(zhuǎn)換為2進(jìn)制
    • 復(fù)接器(多路選擇器)Multiplexer – 根據(jù)One-hot信號選擇某個(gè)輸入信號
    • 仲裁器Arbiter – 選擇第一個(gè)Ture
    • 比較器Comparators – 相等或者幅度大小
    • 只讀存儲器ROMs
  • 采用劃分的方式由小的電路單元構(gòu)造大的電路單元

    Decoder, encoder, multiplexer

  • 基于復(fù)接器和譯碼器的邏輯電路(FPGA中查表的基礎(chǔ))

  • 位片(Bit-slice)編碼風(fēng)格

  • 如何得到求三個(gè)數(shù)的中間數(shù)的電路?復(fù)習(xí)練習(xí)09:寫出這個(gè)電路的VHDL模型总寻。

    1584342453

    vhdl代碼如下所示,復(fù)用三個(gè)比較器梢为,agb代表a大于b渐行,agc代表a大于c轰坊,bgc代表b大于c,三者兩兩之間比較之后祟印,可以得到三者之間得大小關(guān)系肴沫,若a位mid,則agb xor agc為1蕴忆,即a只大于兩個(gè)中的一個(gè)颤芬;若b為mid,agb xor bgc 為0套鹅,也是表示b只大于兩個(gè)中的一個(gè)站蝠,同理若c為mid稠通,agc xor bgc 為1蝇摸,仿真結(jié)果如下圖所示纤壁。result輸出中間的數(shù)甥角,可知結(jié)果正確涣旨。

    1584164213

    代碼如下所示

    library ieee;
    use ieee.std_logic_1164.all;
    use ieee.numeric_std.all;
    use ieee.std_logic_misc.all;
    
    entity magComp is
        generic(k: integer := 8);
        port (
            a,b: in std_logic_vector(k-1 downto 0);
            gt: out std_logic
        ) ;
    end magComp;
    
    architecture impl of magComp is
    
        signal eqi, gti: std_logic_vector(k-1 downto 0);
        signal gta, eqa: std_logic_vector(k downto 0);
    
    
    begin
        eqi <= a xnor b;
        gti <= a and not b;
        gta <= '0' & (gta(k downto 1) or (gti and eqa(k downto 1)));
        eqa <= '1' & (eqa(k downto 1) and eqi);
        gt <= or_reduce(gta);
    end impl ; -- impl
    
    library ieee;
    use ieee.std_logic_1164.all;
    
    entity midle is
        generic(k : integer := 8);
        port (
            a,b,c: in std_logic_vector(k-1 downto 0);
            mid: out std_logic_vector(k-1 downto 0)
        ) ;
    end midle;
    
    architecture impl of midle is
    
        signal agb, agc, bgc: std_logic;
    
    begin
    p1: entity work.magComp generic map(k) port map(a, b, agb);
    p2: entity work.magComp generic map(k) port map(a, c, agc);
    p3: entity work.magComp generic map(k) port map(b, c, bgc);
    
    mid <= a when (agb xor agc) = '1' else
         b when (agb xor bgc)  = '0' else
         c when (agc xor bgc) = '1' else
         (k-1 downto 0 => '-');
    
    end impl ; -- impl
    
    
    --pragma translate_off
    
    library ieee;
    use ieee.std_logic_1164.all;
    use ieee.std_logic_unsigned.all;
    use ieee.numeric_std.all;
    use std.textio.all;
    use ieee.std_logic_textio.all;
    
    
    entity midletest is
    end midletest;
    
    architecture test of midletest is
        signal a, b, c, result: std_logic_vector(3 downto 0);
        
        begin
            p0: entity work.midle generic map (4) port map(a, b, c, result);
            process is
    
            begin
                for i in 0 to 10 loop
                    a <= std_logic_vector(to_signed(i, 4));
                    b <= std_logic_vector(to_signed(i + 1 , 4));
                    c <= std_logic_vector(to_signed(i + 2 , 4));
    
                    wait for 10 ns;
                end loop;
            end process;
    
    end test ; -- test
    --pragma translate_on
    

組合邏輯電路單元的問題: 復(fù)習(xí)練習(xí)10

  • 設(shè)計(jì)一個(gè)組合邏輯電路晚缩,輸入為4個(gè)4-bit One-hot信號愈案, 輸出為4個(gè)信號中最高有效位位置為“1”對應(yīng)的數(shù)字

    如下圖所示银萍,使用比較器跟多路復(fù)用器構(gòu)造電路拔疚,最高有效位為1表示最大的數(shù)肥隆,將a與b,c與d比較稚失,輸出較大的栋艳,在比較這兩個(gè)輸出,選出大的一個(gè)句各。

    1584168059
  • 電路的輸入是4個(gè)4-bit數(shù)字(任意設(shè)定數(shù)據(jù)格式)吸占,輸出是“1的個(gè)數(shù)最少的那個(gè)輸入信號”

    如圖所示,使用比特加法器凿宾,統(tǒng)計(jì)輸入內(nèi)有多少個(gè)1矾屯,在使用與上一題一樣的結(jié)構(gòu),輸出四個(gè)輸入中最小的那個(gè)數(shù)初厚。

    1584168521

復(fù)習(xí)練習(xí)11

  • 設(shè)計(jì)一個(gè)電路件蚕,實(shí)現(xiàn)將輸入a變換成-2a

    • 方法:左移1位 (2x),諸位求反产禾,再+1

      如圖所示的電路排作,將輸入左移兩位,得到輸入的兩倍亚情,在通過與ff異或得到反碼妄痪,在加一的到其補(bǔ)碼電路。

      158416568sad
  • 將10進(jìn)制浮點(diǎn)數(shù)35.6轉(zhuǎn)化為IEEE 754 二進(jìn)制s8.3格式浮 點(diǎn)數(shù)楞件,寫出變換步驟

    我理解成指數(shù)部分3位小數(shù)部分8位的浮點(diǎn)數(shù)衫生,沒有給偏移量僧著,先將整數(shù)部分表示為10 0011,小數(shù)部分表示為0.1001 1001障簿,該數(shù)可以表示為10 0011.1001 1001,格式化為1.0001 1100 1100 * 25 盹愚,故指數(shù)部分為101,s為0站故,故IEEE754格式可以寫成0 101 0001 1100

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末皆怕,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子西篓,更是在濱河造成了極大的恐慌愈腾,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,036評論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件岂津,死亡現(xiàn)場離奇詭異虱黄,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)吮成,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,046評論 3 395
  • 文/潘曉璐 我一進(jìn)店門橱乱,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人粱甫,你說我怎么就攤上這事泳叠。” “怎么了茶宵?”我有些...
    開封第一講書人閱讀 164,411評論 0 354
  • 文/不壞的土叔 我叫張陵危纫,是天一觀的道長。 經(jīng)常有香客問我乌庶,道長种蝶,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,622評論 1 293
  • 正文 為了忘掉前任瞒大,我火速辦了婚禮螃征,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘糠赦。我一直安慰自己会傲,他們只是感情好锅棕,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,661評論 6 392
  • 文/花漫 我一把揭開白布拙泽。 她就那樣靜靜地躺著,像睡著了一般裸燎。 火紅的嫁衣襯著肌膚如雪顾瞻。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,521評論 1 304
  • 那天德绿,我揣著相機(jī)與錄音荷荤,去河邊找鬼退渗。 笑死,一個(gè)胖子當(dāng)著我的面吹牛蕴纳,可吹牛的內(nèi)容都是我干的会油。 我是一名探鬼主播,決...
    沈念sama閱讀 40,288評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼古毛,長吁一口氣:“原來是場噩夢啊……” “哼翻翩!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起稻薇,我...
    開封第一講書人閱讀 39,200評論 0 276
  • 序言:老撾萬榮一對情侶失蹤嫂冻,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后塞椎,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體桨仿,經(jīng)...
    沈念sama閱讀 45,644評論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,837評論 3 336
  • 正文 我和宋清朗相戀三年案狠,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了服傍。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 39,953評論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡骂铁,死狀恐怖伴嗡,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情从铲,我是刑警寧澤瘪校,帶...
    沈念sama閱讀 35,673評論 5 346
  • 正文 年R本政府宣布,位于F島的核電站名段,受9級特大地震影響阱扬,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜伸辟,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,281評論 3 329
  • 文/蒙蒙 一麻惶、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧信夫,春花似錦窃蹋、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,889評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至振湾,卻和暖如春杀迹,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背押搪。 一陣腳步聲響...
    開封第一講書人閱讀 33,011評論 1 269
  • 我被黑心中介騙來泰國打工树酪, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留浅碾,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,119評論 3 370
  • 正文 我出身青樓续语,卻偏偏與公主長得像垂谢,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個(gè)殘疾皇子疮茄,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,901評論 2 355

推薦閱讀更多精彩內(nèi)容