112 年 國立中正大學電機工程學系碩士班晶片系統組《計算機組織》
第 1 題20 分
- (20%) An engineer designs a watching dog timer for MIPS platform using D type flip-flops as follows. With the initial condition , what are the outputs from A0 to A2 at 5th positive clock edge? Why?
🖼️【此處有附圖,請對照原卷】
登入後即可作答並保存紀錄。
核心觀念
圖中的 D 型正反器時脈端有「三角形+反相泡泡」符號,表示它是負緣觸發:只有時脈由高電位降至低電位時,正反器才會取樣 D 輸入並更新輸出。時脈由低電位升至高電位的正緣不會觸發更新。
解題方法
題目問的是第 5 個正時脈緣。逐一檢查每個正緣,因為它們都不是此正反器的觸發邊緣,所以輸出維持初始值。圖中的 Clear 接至 Logic 1,未啟動清除功能。
第 2 題20 分
- (20%) A timing sequence for writing data to the memory is as shown below. Please re-draw a timing sequence with the conditions of (a) memory is triggered by clock's positive edge, (b) write enable is high level triggered, (c) data's hold time is 3/4 T, (d) data's setup time is 1/2 T.
🖼️【此處有附圖,請對照原卷】
登入後即可作答並保存紀錄。
核心觀念
本題考查記憶體寫入時序中的三個基本條件:
-
正緣觸發(positive-edge triggered):記憶體在時脈由低電位轉為高電位的瞬間取樣資料。
-
高電位有效的寫入致能(active-high write enable): 時允許寫入, 時禁止寫入。
-
資料設定時間與保持時間:
- 設定時間 :資料必須在取樣時脈正緣前穩定的時間。
- 保持時間 :資料在取樣正緣後仍須維持穩定的時間。
題目給定:
因此,若記憶體於 的時脈正緣寫入資料,資料必須於 前穩定,並持續穩定至 。
解題方法
以記憶體取樣正緣為時間基準:
- 寫入時脈正緣設定在 。
- 資料由 開始穩定。
- 資料持續到 才能改變。
- 因為 為高電位有效,所以在整個寫入有效期間令 。
- 位址訊號也必須在正緣前穩定,並至少維持至記憶體完成取樣。
所需時序如下:
第 3 題20 分
- (20%) Assume two different CPUs designs running with the same instruction set architecture as shown below. The CPU1 is with a clock rate of 2.5 GHz, and the CPU2 is with a clock rate of 3 GHz. 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.
CPI for each instruction class
| A | B | C | D | |
|---|---|---|---|---|
| CPU1 CPI | 1 | 2 | 3 | 3 |
| CPU2 CPI | 2 | 2 | 2 | 2 |
(a). (10%) Please provide the global CPI for each case?
(b). (10%) What is the clock cycles required for each CPU design?
登入後即可作答並保存紀錄。
核心觀念
整體 CPI 是各指令類別 CPI 的加權平均,權重為該類指令占總指令數的比例:
總時脈週期數則為:
解題方法
CPU1 的整體 CPI:
CPU2 的每類指令 CPI 都是 2,因此:
第 4 題20 分
- (20%) Assume the instructions are as follows, and the bne is determined at the output of the register file.
(a). (10%) Please plot the MIPS five-stage pipeline sequence diagram without forwarding. (10%)
(b). (10%) Please re-plot the diagram of question (a) with forwarding. (10%)
Instructions:
add 21, 9, 20(10, $9, 1000
登入後即可作答並保存紀錄。
參考書等級:大學教材(例:《Computer Organization and Design, MIPS Edition》)
(a) 五階段不轉發流水線時序表
| Cycle → | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| add 21,$9 | IF | ID | EX | MEM | WB | ||||||
| lw 10) | IF | ID | EX | MEM | WB | ||||||
| bne 9,1000 | IF | ID | EX | MEM |
說明
bne的比較在 ID 階段,必須等到add完成 WB($10 已寫回)以及lw完成 WB(
第 5 題20 分
- (20%) Translate the following loop into C. Assume that the C-level integer i is held in register s2 holds the C-level integer called result, and $s0 holds the base address of the integer MemArray.
Instructions:
addi 0, 0
LOOP:
lw s0)
add s2, s0, t1, t2, t2, $s0, LOOP
登入後即可作答並保存紀錄。
核心觀念
本題考查 MIPS 組合語言與 C 語言迴圈、陣列存取及指標位址運算的對應關係:
$0永遠為 。lw $s1, 0($s0):從$s0指向的記憶體位置載入一個整數。- 一個整數占 bytes,因此
$s0 += 4等同於陣列指標前進一格。 slti $t2, $t1, 100會設定:
bne的意思是兩個暫存器內容不相等時跳躍。
題面指令的關鍵問題
題目最後一行寫成:
bne $t2, $s0, LOOP
這會比較條件值 $t2 與記憶體位址 $s0,無法形成「 時繼續迴圈」的正常控制流程。依題意,該行應為:
bne $t2, $0, LOOP
也就是 $t2\ne0$ 時回到 LOOP`。以下依此合理假設說明命題意旨。
逐行解讀
| MIPS 指令 | C 語言意義 |
|---|---|
addi $t1, $0, 0 | i = 0 |
lw $s1, 0($s0) | 讀取目前的 MemArray[i] |
add $s2, $s2, $s1 | result += MemArray[i] |
addi $s0, $s0, 4 | 陣列位址前進一格 |
addi $t1, $t1, 1 | i++ |
slti $t2, $t1, 100 | 計算 i < 100 |
bne $t2, $0, LOOP | 若 i < 100,回到迴圈開頭 |
初始時:
第 次進入迴圈時:
因此 lw 會讀取:
第 次執行完畢後:
此時 slti 產生 $t2=0$,不再跳回 LOOP。
C 語言翻譯