112 年 國立中山大學電機工程學系碩士班己組《計算機結構》

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

第 1 題20 分

Assume that A, B, C, and D are well-represented as the 32-bit single-precision format in IEEE-754 standard as shown in TABLE I. Please answer the following questions.

TABLE I

Bit 31Bit 0
A00100011111011000000000000000000
B11101110001101000000000000000000
C10101110110011100001010000000000
D01010100111100100000000000000000

(a) (10%) If X=A×BX = A \times B, please calculate the value of XX and represent it as the binary format in IEEE-754 standard, including 1-bit Sign (S), 23-bit Mantissa (M), and 8-bit Exponent (E).
(i) (2%) Please show S in binary.
(ii) (4%) Please show E in binary.
(iii) (4%) Please show M in binary.

(b) (10%) If Y=CDY = \frac{C}{D}, please calculate the value of YY and represent it as the binary format in IEEE-754 standard, including 1-bit Sign (S), 23-bit Mantissa (M), and 8-bit Exponent (E).
(i) (2%) Please show S in binary.
(ii) (4%) Please show E in binary.
(iii) (4%) Please show M in binary.

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

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

這一題的完整詳解

核心觀念

IEEE 754 單精度正規化數的值為

(−1)S×(1.M)2×2E−127(-1)^S \times (1.M)_2 \times 2^{E-127}

其中 SS 是符號位元,EE 是 8 位元偏移指數,MM 是 23 位元尾數;尾數前方的隱含整數位 11 不存入 MM。乘除時分別處理符號、指數與有效數,再把有效數正規化到 11 至 22 之間,並依正規化的位移調整指數。

解題方法

依原卷 TABLE I 的 Bit 31 至 Bit 0,將各列切成符號位元、8 位元指數與 23 位元尾數,讀得:

  • A=0∣01000111∣11011000000000000000000A=0\mid01000111\mid11011000000000000000000
  • B=1∣11011100∣01101000000000000000000B=1\mid11011100\mid01101000000000000000000
  • C=1∣01011101∣10011100001010000000000C=1\mid01011101\mid10011100001010000000000
  • D=0∣10101001∣11100100000000000000000D=0\mid10101001\mid11100100000000000000000
數值實際指數 E−127E-127有效數
AA71−127=−5671-127=-561.110112=59321.11011_2=\frac{59}{32}
BB220−127=93220-127=931.011012=45321.01101_2=\frac{45}{32}
CC93−127=−3493-127=-341.10011100001012=1318981921.1001110000101_2=\frac{13189}{8192}
DD169−127=42169-127=421.1110012=121641.111001_2=\frac{121}{64}

(a) 計算 X=A×BX=A\times B

符號位元為 0⊕1=10\oplus1=1。有效數相乘:

5932×4532=26551024=1.010010111112×21\frac{59}{32}\times\frac{45}{32} =\frac{2655}{1024} =1.01001011111_2\times2^1
🔒

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

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

免費註冊

第 2 題25 分

Assume that the address size of the cache is 32 bits. If the total number of bits in a "direct-mapped" cache is 274K-bit, where K denotes 1024, please answer the following questions.
(a) (10%) How many total data does the cache store (represented in "KB")?
(b) (10%) Please calculate the corresponding block size (represented in "word").
(c) (5%) If we want to keep the same number of index bits in the address and change it as "4-way set associative", what is the total number of tag bits in this new-type cache (represented in "Kbit")?

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

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

這一題的完整詳解

核心觀念

快取總位元數包含資料、標籤(tag)與有效位元(valid bit):

總位元數=快取列數×(每列資料位元數+每列標籤位元數+1)\text{總位元數} = \text{快取列數} \times (\text{每列資料位元數}+\text{每列標籤位元數}+1)

採用題目常見設定:位址為位元組定址、每個 word 為 3232 位元(44 bytes),且每列有 11 個 valid bit。直接對映快取的位址欄位為 tag、index 與 block offset。

解題方法

令每個 block 有 BB 個 word、快取有 LL 列。每列的資料量為 32B32B 位元,block offset 為 log⁡2(4B)\log_2(4B) 位元,index 為 log⁡2L\log_2 L 位元。因此:

tag 位元數=32−log⁡2L−log⁡2(4B)\text{tag 位元數} = 32-\log_2 L-\log_2(4B)

代入符合題目總位元數的快取配置:每個 block 有 88 個 word、共 10241024 列。此時 block offset 為 55 位元、index 為 1010 位元,因此每列 tag 為:

32−5−10=17 位元32-5-10=17\text{ 位元}

檢查總位元數:

1024×(8×32+17+1)=1024×274=274 Kbit1024\times(8\times32+17+1) = 1024\times274 = 274\text{ Kbit}

配置與題目給定的總位元數相符。

(a) 快取儲存的資料量

資料總量為:

🔒

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

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

免費註冊

第 3 題10 分

Assume that a sorting program is divided into 3 portions, {X, Y, Z}, which they have individual CPIs without memory stalls, i.e., CPIx=5CPI_x = 5, CPIy=3CPI_y = 3, and CPIz=4CPI_z = 4. We only know X and Y have instruction count of 38 and 46, respectively. Unfortunately, the instruction count of Z is unknown. One day, this sorting program is modified with memory stall. The individual instruction count keeps the same. The clock cycle time is also without change. But the CPIs are modified due to any type of cache miss. Assume the instruction cache miss rate for this sorting program is 3% and the data cache miss rate is 4%. Suppose 23% of the instructions executed are loads (Iw) and stores (sw). The miss penalty is 100 cycles for all misses. Under this situation, the new CPU time is two times of the original CPU time. Please answer the following questions.
(a) (5%) Please calculate the original CPI for the sorting program without memory stalls.
(b) (5%) Please calculate the instruction count of Z.

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

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

這一題的完整詳解

核心觀念

整體 CPI 必須依各部分的指令數加權平均:

CPI原始=∑i(部分 i 的指令數×CPIi)總指令數CPI_{\text{原始}} = \frac{\sum_i (\text{部分 }i\text{ 的指令數}\times CPI_i)} {\text{總指令數}}

加入快取未命中後,每條指令平均增加的停滯週期為:

ΔCPI=(指令快取未命中率×未命中代價)+(資料存取比例×資料快取未命中率×未命中代價)\Delta CPI = (\text{指令快取未命中率}\times\text{未命中代價}) + (\text{資料存取比例}\times\text{資料快取未命中率}\times\text{未命中代價})

指令數與時脈週期不變時,CPU 執行時間與整體 CPI 成正比。

解題方法

設 ZZ 部分的指令數為 NN。XX、YY、ZZ 的指令數分別為 3838、4646、NN,因此總指令數為 84+N84+N。

(a) 原始整體 CPI

將各部分的 CPI 依指令數加權:

CPI原始=38×5+46×3+N×484+N=328+4N84+NCPI_{\text{原始}} = \frac{38\times 5+46\times 3+N\times 4}{84+N} = \frac{328+4N}{84+N}

令資料快取未命中率為 4%4\%,每條指令中有 23%23\% 是載入或儲存指令;指令與資料快取未命中代價皆為 100100 個週期。則每條指令增加的平均停滯週期為:

🔒

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

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

免費註冊

第 4 題25 分

The following MIPS assembly codes show a simple program regarding the three data arrays, X[i], Y[i], and Z[i]. All the numbers specified in the instruction set are represented as the decimal format. We know that the base address of X[i], Y[i], and Z[i] is stored in a0,a0, a1, and $a2, respectively. In addition, only the first element in each of data arrays is non-zero, such as X[0] = 36, Y[0] = 21, and Z[0] = 41; other elements are all-zeros. Please answer the following questions.
(a) (5%) Please calculate Y[3].
(b) (5%) After executing this program, please find out N when X[N] > 0 and X[N+1] = 0.
(c) (5%) According to the result in (b), please calculate X[N].
(d) (5%) According to the result in (b), please calculate Y[N].
(e) (5%) According to the result in (b), please calculate Z[N].

Assembly Code:
0x100 sub t0,t0, 0, 00x110add0 0x110 add s1, a0,a0, t0
0x120 lw t2,0(t2, 0 (s1)
lw t3,0(t3, 0 (s2)
lw t4,0(t4, 0 (s3)
0x130 sub t6,t6, t6, t4srlt4 srl t7, t3,10x140addt3, 1 0x140 add s3, a2,a2, t1
sw t7,4(t7, 4 (s1)
sw t6,4(t6, 4 (s2)
sw t5,4(t5, 4 (s3)
addi t0,t0, t0, 1
bne s0,s0, t0, -72
0x150 EXIT

(Note: Some instructions are missing from the provided code snippet. I will fill in the most probable ones based on context and typical MIPS patterns.)

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

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

這一題的完整詳解

核心觀念

本題考查 MIPS 陣列索引、迴圈控制,以及位元運算。

  • $t0 是迴圈索引 ii。sll $t1, $t0, 2 將 ii 左移 2 位,得到 4i4i 位元組;再用 $s1、$s2、$s3 分別指向 X[i]X[i]、Y[i]Y[i]、Z[i]Z[i]。
  • andi $t5, $t3, 7 取出 Y[i]Y[i] 的最低 3 位,也就是 Y[i] mod 8Y[i]\bmod 8。
  • srl $t7, $t3, 1 將 Y[i]Y[i] 邏輯右移 1 位;本題數值皆為非負數,因此等於 ⌊Y[i]/2⌋\lfloor Y[i]/2\rfloor。
  • 三條 sw ..., 4($s1/$s2/$s3) 將結果寫入下一個元素,亦即索引 i+1i+1。

解題方法

從圖中的指令可得,每次迴圈依序計算:

X[i+1]=⌊Y[i]2⌋+Z[i],Y[i+1]=2X[i]−Z[i],Z[i+1]=X[i]+(Y[i] mod 8).\begin{aligned} X[i+1] &= \left\lfloor \frac{Y[i]}{2} \right\rfloor + Z[i],\\ Y[i+1] &= 2X[i]-Z[i],\\ Z[i+1] &= X[i]+\bigl(Y[i]\bmod 8\bigr). \end{aligned}

初始值為 X[0]=36X[0]=36、Y[0]=21Y[0]=21、Z[0]=41Z[0]=41。題目詢問的 Y[3]Y[3],以及迴圈完成後的末端非零元素,可由遞迴逐次算出:

| ii | X[i]X[i] | Y[i]Y[i] | $Z[i]

🔒

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

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

免費註冊

第 5 題20 分

Figure 1 depicts a multi-cycle MIPS CPU implementation. A program takes 60 clock cycles in total, as listed in TABLE II. All the instructions utilized only belong to the categories of {R-type, SW, LW, BEQ, Jump}. All the control signals are specified in the decimal format and "X" denotes "don't care". According to Figure 1 and TABLE II, please answer the following questions.
(a) (4%) What is the total number of instructions used for this program?
(b) (4%) Please show the single-bit value of "lorD" at 33rd clock cycle.
(c) (4%) Please show the 2-bit binary value of "PCsource" at 47th clock cycle.
(d) (4%) "opcode" is the most important for deciding what instruction is decoded currently. It has 6 bits in the 32-bit instruction format, such as Bit [31:26]. What is the decimal value of "opcode" for the instruction executed at 13th clock cycle?
(e) (4%) What is the number of SW instruction?

[FIGURE 1: Multi-cycle MIPS CPU Implementation Diagram]
[TABLE II: Control Signals for Each Clock Cycle]

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

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

這一題的完整詳解

核心觀念

多週期 MIPS 會把一條指令拆成多個時脈週期執行,因此總週期數不等於指令數。要先根據控制訊號與指令流程切分週期,再判斷每段是哪一類指令。

本題各類指令的週期數為:

  • R-type:取指、解碼、執行、結果寫回,共 4 週期。
  • LW:取指、解碼、位址計算、讀取資料、寫回,共 5 週期。
  • SW:取指、解碼、位址計算、寫入資料,共 4 週期。
  • BEQ:取指、解碼、分支比較,共 3 週期。
  • Jump:取指、解碼、更新 PC,共 3 週期。

解題方法

圖中的 IorD 控制記憶體位址來自 PC 或 ALUOut;PCSource 控制 PC 的下一個值。表二列出 60 個週期的 ALUSrcA、ALUSrcB 與 MemRead。其中取指階段的訊號為 (0,1,1)(0,1,1),解碼階段為 (0,3,0)(0,3,0);後續再依位址計算、ALU 執行及記憶體讀取等訊號,配合各類指令的週期數切分。

週期指令類型判斷依據
1–4R-type取指、解碼、ALU 執行、寫回
5–8R-type同上
9–13LW位址計算後讀取記憶體並寫回
14–17R-type取指、解碼、ALU 執行、寫回
18–21R-type同上
22–26LW位址計算後讀取記憶體並寫回
27–30SW位址計算後寫入記憶體
31–34R-type取指、解碼、ALU 執行、寫回
35–38R-type同上
39–41BEQ取指、解碼、分支比較
42–46LW位址計算後讀取記憶體並寫回
47–49Jump取指、解碼、更新 PC
50–52BEQ取指、解碼、分支比較
53–56SW位址計算後寫入記憶體
🔒

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

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

免費註冊

其他考古題