114 年 國立中正大學電機工程學系碩士班計算機工程組《計算機組織》

📄 試題原卷 免費註冊後即可對照原始考卷 PDF免費註冊

第 1 題20 分

  1. (20%) Assume the MIPS CPU's register is designed as in the diagram below. Please write down the data at (1), (2), (3), (4), and (5) with the conditions for:
    (a) (5%) Normal condition D= 0, Clock= 1 steady, then changes to D= 1, Clock= 0.
    (b) (5%) Normal condition D= 1, Clock= 1 steady, then changes to D= 0, Clock= 1.
    (c) (5%) D= 1, Clock 1 steady, then reset the register.
    (d) (5%) (Q, Q') = (1, 1) in the beginning, next D= 0, Clock = 1 steady.

🖼️【此處有附圖,請對照原卷】
Clock
D
(5)
S
(1)
R
Q
(2) D-(3)-Q'
Reset
(4)

🖼️ 本題含圖表,以下為原卷對應頁面:
原卷第 2 頁

登入後即可作答並保存紀錄。

這一題的完整詳解

核心觀念

本題是由 NAND 閘與交互回授構成的暫存器,不能把它當成「時脈為高電位時,輸出直接跟隨 DD」的電路。判斷各節點時,必須保留回授所儲存的狀態。

NAND 閘的運算為:

Y=X1X2⋯Xn‾Y=\overline{X_1X_2\cdots X_n}

圖中的 Reset 為低電位有效:正常時為 11,重置時拉低為 00。

解題方法

依原圖,六個邏輯閘皆為 NAND 閘;左側四個閘具有交互回授,右側兩個閘構成輸出鎖存器。(1)(1) 是 SS,(2)(2) 是 RR,(3)(3) 是 Q′Q',(4)(4) 是 Reset,(5)(5) 是左下方 NAND 閘的輸出及其回授線。

令左上方 NAND 閘的輸出為 AA、(5)(5) 為 BB,並以 CC 表示 Clock、NN 表示 Reset。依接線可寫成:

A=BS‾,S=ACN‾,R=SCB‾,B=RDN‾,Q=SQ′‾,Q′=RQN‾.\begin{aligned} A&=\overline{BS},\\ S&=\overline{ACN},\\ R&=\overline{SCB},\\ B&=\overline{RDN},\\ Q&=\overline{SQ'},\\ Q'&=\overline{RQN}. \end{aligned}

因此,題目要求的順序為:

((1),(2),(3),(4),(5))=(S,R,Q′,N,B).\bigl((1),(2),(3),(4),(5)\bigr)=(S,R,Q',N,B).

以下將(a)至(c)的正常起始狀態,取為題目所給的 DD 值已經被有效時脈邊緣鎖存。

(a)原先 D=0D=0、Clock =1=1,接著 D=1D=1、Clock =0=0

原先儲存 00,各節點為:

(A,S,R,B,Q,Q′)=(0,1,0,1,0,1).(A,S,R,B,Q,Q')=(0,1,0,1,0,1).

Clock 降為 00 後,兩個包含 Clock 輸入的 NAND 閘皆輸出 11:

S=R=1.S=R=1.

此時 D=1D=1、N=1N=1,所以:

B=1⋅1⋅1‾=0.B=\overline{1\cdot1\cdot1}=0.

右側在 S=R=1S=R=1 時保持原值,故 Q=0Q=0、Q′=1Q'=1。代回輸出方程式亦成立。

(1),(2),(3),(4),(5)=(1,1,1,1,0)\boxed{(1),(2),(3),(4),(5)=(1,1,1,1,0)}

(b)原先 D=1D=1、Clock =1=1,接著 D=0D=0、Clock 仍為 11

原先儲存 11,各節點為:

(A,S,R,B,Q,Q′)=(1,0,1,0,1,0).(A,S,R,B,Q,Q')=(1,0,1,0,1,0).

DD 改為 00 後,左下方輸出變成:

B=R⋅0⋅1‾=1.B=\overline{R\cdot0\cdot1}=1.

但 SS 原先為 00,上方回授仍維持:

A=1⋅0‾=1,S=1⋅1⋅1‾=0.A=\overline{1\cdot0}=1,\qquad S=\overline{1\cdot1\cdot1}=0.

接著:

R=0⋅1⋅1‾=1.R=\overline{0\cdot1\cdot1}=1.

因此 S=0S=0、R=1R=1,右側仍為 Q=1Q=1、Q′=0Q'=0。Clock 持續為 11,沒有新的有效邊緣,因此不會改存 D=0D=0。

🔒

後續完整解題步驟與【答案】

免費註冊,享三天全站完整詳解閱覽。

免費註冊

第 2 題20 分

  1. (20%) Consider two different implementations of the same instruction set architecture. The instructions can be divided into four classes according to their CPI (class A, B, C, and D). P1 with a clock rate of 2.5 GHz and CPIs of 1, 2, 3, and 3, and P2 with a clock rate of 3 GHz and CPIs of 2, 2, 2, and 2. Given a program with a dynamic instruction count of 1.0E6 instructions divided into classes as follows: 10% class A, 20% class B, 50% class C, and 20% class D.
    (a) (10%) What is the global CPI for each implementation?
    (b) (10%) Find the clock cycles required in both cases.
🖼️ 本題含圖表,以下為原卷對應頁面:
原卷第 2 頁

登入後即可作答並保存紀錄。

這一題的完整詳解

核心觀念

本題考查:

  • 全域 CPI(global CPI)的加權平均
  • CPU 所需時脈週期數的計算

全域 CPI 必須依各類指令所占比例加權:

Global CPI=∑i(第 i 類指令比例×第 i 類 CPI)\text{Global CPI} = \sum_i \left( \text{第 }i\text{ 類指令比例} \times \text{第 }i\text{ 類 CPI} \right)

程式執行所需的總時脈週期數為:

Clock Cycles=Instruction Count×Global CPI\text{Clock Cycles} = \text{Instruction Count} \times \text{Global CPI}

題目未要求執行時間,因此時脈頻率不直接影響時脈週期數;時脈頻率只有在計算執行時間時才會使用。

解題方法

(a)各實作的全域 CPI

各類指令比例為:

  • Class A:10%=0.110\% = 0.1
  • Class B:20%=0.220\% = 0.2
  • Class C:50%=0.550\% = 0.5
  • Class D:20%=0.220\% = 0.2

實作 P1

P1 的各類 CPI 為 1,2,3,31,2,3,3,因此:

Global CPIP1=0.1(1)+0.2(2)+0.5(3)+0.2(3)=0.1+0.4+1.5+0.6=2.6\begin{aligned} \text{Global CPI}_{P1} &=0.1(1)+0.2(2)+0.5(3)+0.2(3)\\ &=0.1+0.4+1.5+0.6\\ &=2.6 \end{aligned}

所以:

Global CPIP1=2.6\boxed{\text{Global CPI}_{P1}=2.6}

實作 P2

P2 的四類 CPI 皆為 22:

Global CPIP2=0.1(2)+0.2(2)+0.5(2)+0.2(2)=2(0.1+0.2+0.5+0.2)=2\begin{aligned} \text{Global CPI}_{P2} &=0.1(2)+0.2(2)+0.5(2)+0.2(2)\\ &=2(0.1+0.2+0.5+0.2)\\ &=2 \end{aligned}
🔒

後續完整解題步驟與【答案】

免費註冊,享三天全站完整詳解閱覽。

免費註冊

第 3 題20 分

  1. (20%) Consider the following MIPS loop as:
    LOOP: slt t2,t2, 0, t1beqt1 beq t2, 0,DONEsubi0, DONE subi t1, t1,1addit1, 1 addi s2, s2,2jLOOPDONE:(a).(10s2, 2 j LOOP DONE: (a). (10%) Assume that the register t1 is initialized to the value 10. What is the value in register s2assumingthes2 assuming the s2 is initially zero?
    (b). (10%) For each of the loops above, write the equivalent C code routine. Assume that the registers s2,s2, t1, and $t2 are integers B, i, and temp, respectively.
🖼️ 本題含圖表,以下為原卷對應頁面:
原卷第 3 頁

登入後即可作答並保存紀錄。

這一題的完整詳解

核心觀念

slt $t2, $0, $t1 會在 $t1 > 0 時將 $t2 設為 1,否則設為 0。接著 beq $t2, $0, DONE 在 $t2=0 時跳出迴圈;只有 $t1>0 時,才會執行遞減 $t1 與累加 $s2。

解題方法

每次迴圈先檢查 $t1 是否大於 0。若成立,執行:

  • $t1 \leftarrow $t1 - 1
  • $s2 \leftarrow $s2 + 2

初始 $t1=10,因此更新與累加各執行 10 次。由 $s2=0$ 開始:

$s2 = 0 + 10 \times 2 = 20

迴圈結束時 $t1=0$,下一次檢查使 $t2=0$,程式跳至 DONE。

等價 C 程式與複雜度

🔒

後續完整解題步驟與【答案】

免費註冊,享三天全站完整詳解閱覽。

免費註冊

第 4 題20 分

  1. (20%) Please calculate follows in binary and then represent in IEEE 754 single precision binary formats:
    (a). (10%) -0.4375×0.75, (b). (10%) 2.75 / 0.125.
🖼️ 本題含圖表,以下為原卷對應頁面:
原卷第 3 頁

登入後即可作答並保存紀錄。

這一題的完整詳解

本題考查浮點數的二進位轉換與 IEEE 754 單精度格式表示。

核心觀念:

  1. 十進位轉二進位:
    • 整數部分:使用除以 2 取餘數法。
    • 小數部分:使用乘以 2 取整數部分法。
  2. IEEE 754 單精度格式:
    • 共 32 位元。
    • 符號位元 (Sign bit, S):1 位元。0 為正,1 為負。
    • 指數位元 (Exponent bits, E):8 位元。採用偏移表示法 (biased representation),偏移值為 127。實際指數 e=E−127e = E - 127。
    • 尾數/分數位元 (Mantissa/Fraction bits, F):23 位元。表示規格化數字時,隱含一個前導的 '1'。數字形式為 (−1)S×(1.F)2×2e(-1)^S \times (1.F)_2 \times 2^e。
  3. 浮點數乘法與除法:
    • 乘法:
      • 符號:相乘。
      • 指數:相加 (加上偏移值)。
      • 尾數:相乘。
    • 除法:
      • 符號:相除。
      • 指數:相減 (減去偏移值)。
      • 尾數:相除。
    • 結果正規化:乘法或除法後,結果的尾數可能需要正規化,調整指數。

(a) -0.4375 × 0.75

步驟 1:將十進位數轉換為二進位

  • -0.4375

    • 符號:負數,S = 1。
    • 0.4375:
      • 0.4375×2=0.8750.4375 \times 2 = 0.875 (整數部分 0)
      • 0.875×2=1.750.875 \times 2 = 1.75 (整數部分 1)
      • 0.75×2=1.50.75 \times 2 = 1.5 (整數部分 1)
      • 0.5×2=1.00.5 \times 2 = 1.0 (整數部分 1)
    • 所以,0.437510=0.011120.4375_{10} = 0.0111_2。
    • 正規化:0.01112=1.112×2−20.0111_2 = 1.11_2 \times 2^{-2}。
    • 指數 e=−2e = -2。
    • 偏移指數 E=e+127=−2+127=125E = e + 127 = -2 + 127 = 125。
    • 二進位表示 12510125_{10}:125=64+32+16+8+4+1=011111012125 = 64 + 32 + 16 + 8 + 4 + 1 = 01111101_2。
    • 尾數 FF:1.1121.11_2 的小數部分是 11000000000000000000000211000000000000000000000_2 (共 23 位)。
    • 所以,−0.437510-0.4375_{10} 的 IEEE 754 表示為:1 01111101 11000000000000000000000
  • 0.75

    • 符號:正數,S = 0。
    • 0.75:
      • 0.75×2=1.50.75 \times 2 = 1.5 (整數部分 1)
      • 0.5×2=1.00.5 \times 2 = 1.0 (整數部分 1)
    • 所以,0.7510=0.1120.75_{10} = 0.11_2。
    • 正規化:0.112=1.12×2−10.11_2 = 1.1_2 \times 2^{-1}。
    • 指數 e=−1e = -1。
    • 偏移指數 E=e+127=−1+127=126E = e + 127 = -1 + 127 = 126。
    • 二進位表示 12610126_{10}:126=64+32+16+8+4+2=011111102126 = 64 + 32 + 16 + 8 + 4 + 2 = 01111110_2。
    • 尾數 FF:1.121.1_2 的小數部分是 10000000000000000000000210000000000000000000000_2 (共 23 位)。
    • 所以,0.75100.75_{10} 的 IEEE 754 表示為:0 01111110 10000000000000000000000

步驟 2:計算乘法

  • 符號 (S):負數 ×\times 正數 = 負數。所以結果的 S = 1。
  • 指數 (E):
    • 結果的實際指數 eres=e1+e2=(−2)+(−1)=−3e_{res} = e_1 + e_2 = (-2) + (-1) = -3。
    • 結果的偏移指數 Eres=eres+127=−3+127=124E_{res} = e_{res} + 127 = -3 + 127 = 124。
    • 二進位表示 12410124_{10}:124=64+32+16+8+4=011111002124 = 64 + 32 + 16 + 8 + 4 = 01111100_2。
  • 尾數 (F):
    • 兩個數的尾數部分是 1.1121.11_2 和 1.121.1_2。
    • 將它們乘以:1.112×1.121.11_2 \times 1.1_2。
    • 1.112=1+1/2+1/4=1.75101.11_2 = 1 + 1/2 + 1/4 = 1.75_{10}。
    • 1.12=1+1/2=1.5101.1_2 = 1 + 1/2 = 1.5_{10}。
    • 1.75×1.5=2.625101.75 \times 1.5 = 2.625_{10}。
    • 將 2.625102.625_{10} 轉換為二進位:
      • 210=1022_{10} = 10_2。
      • 0.625×2=1.250.625 \times 2 = 1.25 (整數部分 1)
      • 0.25×2=0.50.25 \times 2 = 0.5 (整數部分 0)
      • 0.5×2=1.00.5 \times 2 = 1.0 (整數部分 1)
    • 所以,2.62510=10.10122.625_{10} = 10.101_2。
    • 正規化:10.1012=1.01012×2110.101_2 = 1.0101_2 \times 2^1。
    • 結果的實際指數是 eres=1e_{res} = 1。
    • 檢查指數計算是否一致:我們之前計算的 eres=−3e_{res} = -3。這裡計算出 eres=1e_{res} = 1。這是因為尾數相乘後需要正規化,這會改變指數。
    • 正確的指數計算方法:
      • e1=−2e_1 = -2, e2=−1e_2 = -1。
      • 相乘的尾數是 1.1121.11_2 和 1.121.1_2。
      • (1.112×2−2)×(1.12×2−1)=(1.112×1.12)×2−2+(−1)(1.11_2 \times 2^{-2}) \times (1.1_2 \times 2^{-1}) = (1.11_2 \times 1.1_2) \times 2^{-2 + (-1)}
      • 1.112×1.12=10.10121.11_2 \times 1.1_2 = 10.101_2。
      • 正規化 10.1012=1.01012×2110.101_2 = 1.0101_2 \times 2^1。
      • 所以,結果是 (1.01012×21)×2−3=1.01012×2−2(1.0101_2 \times 2^1) \times 2^{-3} = 1.0101_2 \times 2^{-2}。
      • 實際指數 eres=−2e_{res} = -2。
      • 偏移指數 Eres=eres+127=−2+127=125E_{res} = e_{res} + 127 = -2 + 127 = 125。
      • 二進位表示 12510125_{10}:01111101201111101_2。
    • 尾數 FF:1.010121.0101_2 的小數部分是 01010000000000000000000201010000000000000000000_2 (共 23 位)。

步驟 3:組合 IEEE 754 表示

  • S = 1
  • E = 01111101
  • F = 01010000000000000000000

最終結果:1 01111101 01010000000000000000000

🔒

後續完整解題步驟與【答案】

免費註冊,享三天全站完整詳解閱覽。

免費註冊

第 5 題20 分

  1. (20%) we assume that the following MIPS code is executed on a pipelined processor with a 5-stage
    pipeline, full forwarding, and a predict-taken branch predictor:
    lw r2, 0(r1)
    label1: beq r2, r0, label2 # not taken once, then taken
    lw r3, 0(r2)
    beq r3, r0, labell # taken
    and r1, r3, rl
    label2: sw r1, 0(r2)
    (a). (10%) Draw the pipeline execution diagram for this code, assuming there are no delay slots and that
    branches execute in the EX stage.
    (b). (10%) Repeat question (a), but assume that delay slots are used. In the given code, the instruction that
    follows the branch is now the delay slot instruction for that branch.
🖼️ 本題含圖表,以下為原卷對應頁面:
原卷第 3 頁

登入後即可作答並保存紀錄。

這一題的完整詳解

核心觀念

五級 MIPS 管線依序為 IF(取指)、ID(解碼與讀暫存器)、EX(運算)、MEM(記憶體存取)、WB(寫回)。

本題須同時處理三件事:

  1. 載入後立即使用的資料相依:即使有完整轉送,lw 的資料仍要到 MEM 結束才產生。因此緊接著使用載入結果的 beq,必須停滯一個週期。
  2. 預測跳躍與誤預測:分支在 EX 結束時確認結果;若預測錯誤,清除錯誤路徑,下一個週期就取正確路徑的指令。
  3. 分支延遲槽:有延遲槽時,分支後面緊接的一條指令,不論分支是否跳躍都必須執行;預測的目標指令在延遲槽之後取指。

解題方法

原卷指定:第一個 beq r2, r0, label2 第一次不跳、第二次跳;第二個 beq r3, r0, label1 跳躍。第二個分支的目標是 label1,其後指令是 and r1, r3, r1。

採用分支目標可立即供取指使用的時序:無延遲槽時,分支取指後下一週期取預測目標;有延遲槽時,先取延遲槽,再取預測目標。假設指令與資料記憶體不發生結構冒險。

以下用代號表示指令:

代號指令
AAlw r2, 0(r1)
B1、B2B_1、B_2第一次、第二次執行 beq r2, r0, label2
C1、C2C_1、C_2第一次、第二次執行 lw r3, 0(r2)
DDbeq r3, r0, label1
EEand r1, r3, r1
SS正確路徑的 sw r1, 0(r2)
S錯S_{\mathrm{錯}}誤預測路徑的 sw r1, 0(r2)

表中的「停」表示停滯或保持,「×」表示該指令於該週期結束被清除;分支列中的 MEM、WB 僅表示通過管線階段,沒有記憶體存取或暫存器寫回。

(a) 無延遲槽

實際執行的指令順序為:

A→B1→C1→D→B2→SA \rightarrow B_1 \rightarrow C_1 \rightarrow D \rightarrow B_2 \rightarrow S
  • AA 的載入結果於 cycle 4 的 MEM 結束產生,故 B1B_1 在 cycle 4 停留於 ID,於 cycle 5 的 EX 使用轉送資料。
  • B1B_1 被預測為跳躍,先取到 S錯S_{\mathrm{錯}};cycle 5 確認不跳後,清除錯誤路徑,cycle 6 立即取 C1C_1。
  • C1C_1 與 DD 又形成載入後立即使用的相依,因此 DD 停滯一個週期,在 cycle 10 的 EX 判定跳躍。
  • DD 預測正確,已取到目標 B2B_2;B2B_2 也預測正確,最後執行 SS。and 不會執行。
指令\週期12345678910111213
AAIFIDEXMEMWB————————
B1B_1—IFIDID停EXMEMWB——————
S錯S_{\mathrm{錯}}——IFIF停ID×————————
C1C_1—————IFIDEXMEMWB———
DD——————IFIDID停EXMEMWB—
B2B_2———————IFIF停IDEXMEMWB
SS—————————IFIDEXMEM

因此,最後的 sw 於 cycle 13 的 MEM 完成寫入。

(b) 使用一個分支延遲槽

🔒

後續完整解題步驟與【答案】

免費註冊,享三天全站完整詳解閱覽。

免費註冊

其他考古題