111 年 國立陽明交通大學資訊工程學系碩士班《計算機系統》

第 1 題

Consider the following C code. Which outputs are possible?

(A) ABCED.
(B) AEBCD.
(C) ABDCE.
(D) AEBDC.

int main() {
    printf("A");
    if (fork() == 0) {
        usleep(((rand() % 5) + 1) * 10000); /* wait for a random time */
        printf("B");
        if (fork() == 0) {
            usleep(((rand() % 5) + 1) * 10000); /* wait for a random time */
            printf("C");
        }
        else {
            wait(NULL);
            printf("D");
        }
    }
    else {
        usleep(((rand() % 5) + 1) * 10000); /* wait for a random time */
        printf("E");
        wait(NULL);
    }
    return 0;
}

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

這一題的完整詳解

核心觀念

fork() 會複製目前程序,父、子程序之後各自執行。fork() 回傳值為 0 的程序走子程序分支,另一個程序走父程序分支。

本題用 wait() 建立程序間的先後關係:

  • 子程序印出 B 後再建立孫程序;孫程序印出 C。
  • 子程序等待孫程序結束後才印出 D,所以 CC 一定在 DD 之前。
  • 原始父程序印出 E,並等待子程序結束;這只限制父程序何時結束,不會固定 EE 與 B,C,DB,C,D 的相對順序。

因此,先將必定的輸出順序整理為:

A≺B≺C≺DA \prec B \prec C \prec D

其中 EE 在 B,C,DB,C,D 之前、之間或之後都可能出現,實際位置由排程與延遲決定。

解題方法

把程序分支轉成輸出先後關係:

🔒

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

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

免費註冊

第 2 題

Consider a system with 15 resources and 4 threads: T0T_0, T1T_1, T2T_2, and T3T_3. The second column in the following table shows the maximum number of resources needed by each thread, and the third column shows the number of resources each thread is currently holding. Let x^\hat{x} be the maximum value of xx (shown below) that can still keep the system in a safe state. Which statements are correct?

ThreadMaximum NeedsCurrent Needs
T0T_053
T1T_141
T2T_295
T3T_3xx4

(A) x^=13\hat{x}=13.
(B) With x^\hat{x}, ⟨T0,T1,T2,T3⟩\langle T_0,T_1,T_2,T_3\rangle is a safe sequence.
(C) Even for some value of xx that makes the system in an unsafe state, it may not lead to a deadlock.
(D) The way we use here to see whether a system is safe only applies to one type of resource. The banker's algorithm extends it to multiple types of resources.

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

這一題的完整詳解

核心觀念

本題考查安全狀態與安全序列。系統目前有 15 個同類資源;每個執行緒的「最大需求」是它最多會同時持有的資源數,「目前持有」是已分配的資源數。

每個執行緒尚需資源數為:

Need=Maximum−Allocation\text{Need}=\text{Maximum}-\text{Allocation}

檢查安全狀態時,從目前可用資源數開始,依序尋找尚需資源數不超過可用量的執行緒。假設它完成後會釋放目前持有的資源,更新可用量,再檢查下一個執行緒。若所有執行緒都能依此完成,就存在安全序列,系統處於安全狀態。

解題方法

目前已分配資源總數為:

3+1+5+4=133+1+5+4=13

所以可用資源數為:

15−13=215-13=2

各執行緒尚需資源數如下:

執行緒尚需資源數
T0T_05−3=25-3=2
T1T_14−1=34-1=3
T2T_29−5=49-5=4
T3T_3x−4x-4

以題目指定的順序 ⟨T0,T1,T2,T3⟩\langle T_0,T_1,T_2,T_3\rangle 檢查:

  1. 起初有 2 個可用資源,足以滿足 T0T_0 尚需的 2 個。T0T_0 完成後釋放 3 個,故可用量變為 2+3=52+3=5。
  2. T1T_1 尚需 3 個,5 個可用資源足以滿足。完成後可用量變為 5+1=65+1=6。
  3. T2T_2 尚需 4 個,6 個可用資源足以滿足。完成後可用量變為 6+5=116+5=11。
🔒

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

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

免費註冊

第 3 題

Which statements about semaphore are correct?

(A) Two processes sharing two common binary semaphores may result in a deadlock.
(B) If we use a binary semaphore to implement a mutex lock, the semaphore should be initialized to 0.
(C) If we invoke an x.signal()x.\mathrm{signal}() operation on a condition variable xx but no process is suspended on xx, then the state of xx remains unchanged.
(D) If we invoke a signal(S)\mathrm{signal}(S) operation on a semaphore SS but no process is suspended on SS, then the state of SS remains unchanged.

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

這一題的完整詳解

核心觀念

本題考查信號量與條件變數的操作語意,以及以信號量實作互斥鎖時的初始值。

對計數信號量 SS,常見定義為:

  • wait(S)\mathrm{wait}(S):有可用資源時將 SS 減一;沒有可用資源時,呼叫程序等待。
  • signal(S)\mathrm{signal}(S):若有程序正在等待,喚醒其中一個;若沒有程序等待,則將 SS 加一。

互斥鎖必須在一開始允許一個程序進入臨界區,因此用二元信號量實作時,初值應設為 11。

條件變數的訊號則不同:呼叫 x.signal()x.\mathrm{signal}() 時,若沒有程序正在 xx 上等待,就不會把訊號保留下來供日後使用。

解題方法

逐項區分三件事:兩個信號量的取得順序是否會形成循環等待、互斥鎖初值是否允許首次進入,以及「沒有等待者時呼叫 signal」對條件變數和信號量各自有何效果。

選項分析

(A) 正確。
兩個程序共用兩個二元信號量 S1S_1、S2S_2,若兩者初值皆為 11,且程序以不同順序取得它們,就可能形成死結:

  1. 程序 P1P_1 先執行 wait(S1)\mathrm{wait}(S_1),取得 S1S_1。
  2. 程序 P2P_2 先執行 wait(S2)\mathrm{wait}(S_2),取得 S2S_2。
  3. P1P_1 執行 wait(S2)\mathrm{wait}(S_2),因 S2S_2 已被 P2P_2 持有而等待。
🔒

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

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

免費註冊

第 4 題

A process could be in new, running, waiting, ready, or terminated state. Which statements about process states are correct?

(A) If a process invokes a blocking send()\mathrm{send}() for message passing, the process will enter the waiting state.
(B) When a process must wait on a spin-lock, the process will enter the waiting state.
(C) A process kept staying in the waiting state will not incur context-switching overhead.
(D) A wakeup()\mathrm{wakeup}() operation changes the state of a process from the waiting state to the running state.

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

這一題的完整詳解

核心觀念

行程狀態描述行程目前能否使用 CPU,以及是否正在等待某個事件:

  • 執行中(running):正在 CPU 上執行。
  • 就緒(ready):可使用 CPU,正在等待排程器分配 CPU。
  • 等待(waiting/blocked):必須等某個事件發生,才能繼續執行。

阻塞式 I/O 或訊息傳送若尚未完成,行程會進入等待狀態。自旋鎖則採用忙等待:行程反覆檢查鎖是否可用,仍在消耗 CPU,不屬於等待狀態。等待事件完成後,行程先從等待轉為就緒,再由排程器選中後轉為執行中。

解題方法

逐項對照行程狀態的定義,特別區分「等待事件」與「忙等待」,以及 wakeup() 喚醒後的「就緒」和「執行中」。

選項分析

🔒

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

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

免費註冊

第 5 題

Which statements about CPU scheduling are correct?

(A) Compared with first-come first-serve (FIFO), nonpreemptive shortest-job-first scheduling results in fewer context switches.
(B) Shortest-remaining-time-first scheduling can lead to starvation.
(C) A voluntary context switch occurs to a process when its time slice has expired.
(D) Processor affinity, which tries keeping a thread running on the same processor, is a load-balancing technique for multiprocessor scheduling in a symmetric multiprocessing (SMP) system.

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

這一題的完整詳解

核心觀念

本題考查排程演算法的搶先性、飢餓,以及多處理器排程中的處理器親和性。

  • 非搶先式最短工作優先(SJF):每次挑選預估 CPU 執行時間最短的就緒行程執行;一旦開始執行,通常會持續到完成或自行阻塞。
  • 最短剩餘時間優先(SRTF):SJF 的搶先式版本。新行程到達時,若其執行時間短於目前行程的剩餘時間,排程器可搶先切換至新行程。
  • 飢餓(starvation):某行程長時間無法取得 CPU。若短工作持續到達,長工作可能一再被延後。
  • 自願式與非自願式內容切換:行程因阻塞、完成等原因主動讓出 CPU,屬自願式;時間片用盡而被排程器搶先,屬非自願式。
  • 處理器親和性(processor affinity):盡量讓執行緒留在同一顆處理器上,以提升快取命中率。它可能影響負載平衡,但本身不是負載平衡技術。

解題方法

逐一檢查各敘述中的關鍵性質:

  1. 比較兩種排程的內容切換次數是否必然不同。
  2. 判斷搶先式 SJF 是否會使長工作等待過久。
  3. 分辨時間片到期是行程主動讓出 CPU,還是被系統搶先。
  4. 區分處理器親和性與負載平衡的目的。

選項分析

🔒

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

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

免費註冊

第 6 題

In addition to a reference bit, a modify bit can be added to form the bit pair (reference, modify) associated with a page to improve the second-chance algorithm used in page replacement, where the reference bit is 1 if the page has been referenced and the modify bit is 1 if the page has been updated in the past round. Divide the pages into four classes: (0,0)(0,0), (0,1)(0,1), (1,0)(1,0), and (1,1)(1,1).

(A) Both reference bit and modify bit, if being 1, are cleared to 0 on a circular round of the page replacement algorithm, as a way to give the second chance.
(B) Pages in class (0,0)(0,0) should be replaced first, while the pages in class (1,1)(1,1) should be replaced last.
(C) Pages in class (0,1)(0,1) should be replaced before pages in class (1,0)(1,0).
(D) Pages in class (0,1)(0,1), if picked to replace and dirty, should be written out before replacement.

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

這一題的完整詳解

核心觀念

本題考「增強型第二次機會頁面置換」(enhanced second-chance page replacement)。每個頁面以參考位元 RR 與修改位元 MM 分類:

  • R=1R=1:頁面近期曾被存取。
  • M=1M=1:頁面曾被寫入,內容與磁碟上的版本不同,換出前需要寫回磁碟。

演算法偏好替換近期未使用、且不必寫回磁碟的頁面。四類的替換優先順序為:

(0,0)  ≺  (0,1)  ≺  (1,0)  ≺  (1,1)(0,0)\; \prec\; (0,1)\; \prec\; (1,0)\; \prec\; (1,1)

越靠左,越優先替換。掃描時會清除參考位元 RR,讓頁面取得第二次機會;修改位元 MM 則不會因為掃描一輪就清除。

解題方法

逐一對照各選項與上述規則:

  1. 確認第二次機會是透過清除參考位元 RR 實現。
  2. 依四類替換順序判斷各類的先後。
  3. 對 M=1M=1 的頁面,確認替換前須先寫回磁碟。

選項分析

(A) 錯誤。
掃描一輪時,演算法清除的是參考位元 RR,讓頁面下一輪有機會以 R=0R=0 被考慮。

🔒

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

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

免費註冊

第 7 題

Consider memory-mapped files where disk blocks of a file are mapped to pages in memory, so that file I/O can be treated as routine memory access.

(A) To load a file into memory, the mmap()\mathrm{mmap}() system call loads initially the entire file into the memory pages.
(B) By default, a memory-mapped file is mapped into the user process address space, instead of the kernel space.
(C) After invoking mmap()\mathrm{mmap}(), read()\mathrm{read}() and write()\mathrm{write}() system calls are automatically translated by the kernel into memory access instructions.
(D) If the standard I/O is memory-mapped by mmap()\mathrm{mmap}(), the mapping will be to kernel address space instead of user address space, and thus read()\mathrm{read}() and write()\mathrm{write}() would trigger memory copy between kernel space and user space.

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

這一題的完整詳解

核心觀念

mmap() 將檔案的一段內容映射到呼叫程序的虛擬位址空間。程序可以像存取記憶體一樣讀寫映射區域;實際檔案頁面通常採需求載入,首次存取尚未載入的頁面時,會引發缺頁例外,再由作業系統載入資料。

映射檔案與 read()、write() 是兩種不同的檔案存取方式:

  • 使用 mmap() 時,程序透過記憶體存取指令讀寫映射區域。
  • 使用 read()、write() 時,程序仍呼叫系統呼叫,由核心在檔案與程序提供的緩衝區之間傳送資料。

解題方法

逐項判斷 mmap() 的映射位置、載入時機,以及它是否會改變 read()、write() 的行為。關鍵是分清楚「核心管理檔案頁面」與「映射出現在程序的哪個位址空間」:核心負責管理頁面,但映射通常位於呼叫程序的使用者位址空間。

選項分析

(A) 錯誤。
呼叫 mmap() 不代表整個檔案會立即載入記憶體。作業系統通常採需求分頁:建立映射後,只有在程序實際存取某個頁面時,該頁面才會載入。未被存取的檔案頁面不必進入記憶體。

🔒

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

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

免費註冊

第 8 題

A file can be stored in a file system with different allocation methods: contiguous, extent-based, linked, or indexed. Suppose directories are already in memory. An extent has an average of 16 blocks. Assume that a file has 512 blocks, numbered from 0 to 511, and the target of a random access read is block 239.

(A) With contiguous allocation, only one block needs to be read in order to access block 239.
(B) With extent-based allocation, 15 blocks need to be read in order to access block 239.
(C) With linked allocation, 240 blocks need to be read in order to access block 239.
(D) With indexed allocation, 2 blocks need to be read in order to access block 239.

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

這一題的完整詳解

核心觀念

本題比較四種檔案配置法進行隨機讀取時,需要讀取多少個磁碟區塊。題目已說明目錄在記憶體中,因此目錄查找不計入磁碟讀取次數。

  • 連續配置:檔案區塊連續,可由起始區塊位置直接算出目標位置。
  • Extent 配置:檔案由多段連續區塊組成;每段稱為一個 extent。依課本(Silberschatz)的描述,目錄只記錄第一段 extent 的位置與長度,每段 extent 再以一個連結指向下一段。
  • 鏈結配置:每個區塊含有下一個區塊的指標,須從檔案開頭沿鏈結前進。
  • 索引配置:先讀取索引區塊,再依索引讀取目標資料區塊。

解題方法

題目中的 block 239 是從 0 開始編號,因此它是第 240 個區塊。

在 Extent 配置下,平均每段有 16 個區塊:

⌊23916⌋=14\left\lfloor \frac{239}{16} \right\rfloor = 14

所以 block 239 位於第 15 段 extent(由 1 開始計數),且是該段的最後一個區塊。記憶體中的目錄只知道第 1 段在哪裡,要找到第 15 段,得依序讀出第 1~14 段中存放「下一段位置」的那個區塊(14 次),再讀 block 239 本身(1 次),共 15 次。

選項分析

🔒

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

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

免費註冊

第 9 題

Consider UNIX UFS with 4 KB blocks. In an inode, suppose there are 2048 entries in the “direct block” pointing to at most 2048 data blocks. There is also an entry for each of “single indirect”, “double indirect”, and “triple indirect”, pointing to an indirect node with 2048 entries for data blocks or recursively indirect nodes.

(A) With only direct block, the maximum file size is around 8 MB.
(B) With direct block and single indirect, the maximum file size is around 16 MB.
(C) With direct block, single indirect, and double indirect, the maximum file size is around 16 GB.
(D) With direct block, single indirect, double indirect, and triple indirect, the maximum file size is around 32 TB.

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

這一題的完整詳解

核心觀念

UFS 的 inode 以多層指標記錄資料區塊位置。本題的設定:區塊 4 KB=2124\text{ KB}=2^{12} bytes;直接區塊有 2048=2112048=2^{11} 個項目;每個間接節點也有 2112^{11} 個項目。各層可指到的資料區塊數:

層資料區塊數容量
直接2112^{11}211×212=2232^{11}\times2^{12}=2^{23} B =8=8 MB
單重間接2112^{11}88 MB
雙重間接2222^{22}2342^{34} B =16=16 GB
三重間接2332^{33}2452^{45} B =32=32 TB

選項分析

🔒

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

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

免費註冊

第 10 題

Consider various mechanisms used in Linux. Which statements are valid?

(A) A dynamically loaded kernel module will not be unloaded automatically by the kernel unless explicitly requested.
(B) The kernel maintains a table of functions for loading programs of different binary formats, and tries them one by one when loading an executable binary.
(C) Slab allocation is for contiguous memory allocation needed for user processes.
(D) For a library of functions statically linked to multiple programs, it is loaded into memory multiple times as multiple copies, but only once and one copy if dynamically linked.

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

這一題的完整詳解

核心觀念

本題考查 Linux 的核心模組管理、可執行檔格式辨識、核心記憶體配置,以及靜態與動態連結的差異。

解題方法

逐項對照機制的用途與作用範圍:

  • 核心模組在載入後是否會自行卸載。
  • 核心如何辨識不同格式的可執行檔。
  • slab 配置器服務的對象。
  • 靜態連結與動態連結如何影響程式間的程式庫共享。

選項分析

(A) 正確。
動態載入的核心模組載入後會留在核心中,直到被明確要求卸載,例如使用 rmmod 或 modprobe -r。核心會追蹤模組的使用狀態;模組仍被使用時,卸載請求會受到阻止。核心不會只因為模組暫時沒有使用者,就自動將它卸載。

(B) 正確。
Linux 核心可註冊多種可執行檔格式處理器,例如 ELF 格式處理器。載入程式時,核心會依序交由已註冊的處理器判斷;

🔒

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

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

免費註冊

第 11 題

For instruction set architecture (ISA), which of the following statements are true?

(A) RISC CPUs usually use fixed and simple instruction formats, which may offer better execution efficiency for pipelining than CISC CPUs.
(B) The choice of big/little endian determines the memory ordering and is nothing to do with the ISA design.
(C) The purpose of Open ISA is to allow “open source” of CPU RTL codes.
(D) An ISA keeping the source (rs1 and rs2) and destination (rd) registers at the same position in all formats can simplify decoding (such as RISC-V), whereas MIPS has overlapped fields for rs2 and rd, which needs multiplexors.

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

這一題的完整詳解

核心觀念

ISA(指令集架構)定義處理器可執行的指令,以及程式可觀察到的規則,例如指令格式、暫存器、資料型態與記憶體存取方式。這題考查指令格式如何影響管線解碼、位元組序是否屬於 ISA 設計,以及「開放 ISA」的含義。

解題方法

逐項檢查各敘述中的關鍵主張:

  1. 指令格式固定且欄位位置規則,是否有利於解碼與管線化?
  2. 大端序與小端序是否完全獨立於 ISA?
  3. 開放 ISA 指的是開放規格,還是必須公開處理器 RTL?
  4. 比較 RISC-V 與 MIPS 的暫存器欄位位置,確認解碼時是否需要選擇器。

選項分析

(A) 正確。
RISC 處理器常採用固定長度、格式較規則的指令。解碼器較容易在固定位置辨識操作碼與暫存器欄位,也較容易讓多個管線階段平行運作,因此通常有利於管線化。相較之下,部分 CISC 指令長度不固定、格式較多樣,解碼工作可能較複雜。

(B) 錯誤。
大端序與小端序定義多位元組資料在記憶體中的排列方式:大端序將最高有效位元組放在較低位址,小端序則將最低有效位元組放在較低位址。

🔒

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

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

免費註冊

第 12 題

Given the normal 1-bit ALU (top) and the MSB 1-bit ALU (bottom), you can implement the C-language statement by giving the tuple (Ainvert,Binvert,CarryIn,Operation)(\mathrm{Ainvert},\mathrm{Binvert},\mathrm{CarryIn},\mathrm{Operation}). Each AA, BB, and CC represents 4 bits wide. For condition determination, CC is 0001 if TRUE, and is 0000 if FALSE. For example, give (0,0,0,2)(0,0,0,2) for C=A+BC=A+B.

🖼️【此處有附圖,見下方】

(A) By giving appropriate tuples, we can make possible statements: C=A−BC=A-B; C=B−AC=B-A, but not possible for C=A−B−1C=A-B-1 and C=B−A−1C=B-A-1, which need an additional subtractor.
(B) For C=A<BC=A<B, let us give (0,1,1,3)(0,1,1,3) and also connect set to Less0. All other Less13 are set 0.
(C) For C=A>BC=A>B, let us give (0,1,1,3)(0,1,1,3) and also connect set to Less0. All other Less1
3 are set 0.
(D) For D=(A==B)D=(A==B), let us give (0,1,1,2)(0,1,1,2) and also connect all C0∼C3C_0\sim C_3 to a NOR gate to obtain the final D0D_0. All Less0~3 are set 0 and connect other C1∼C3C_1\sim C_3 to D1∼D3D_1\sim D_3.

🖼️ 本題附圖:
第 12 題附圖

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

這一題的完整詳解

核心觀念

本題考查 1 位元 ALU 串接成 4 位元 ALU 時,如何利用輸入反相、進位與輸出選擇,完成減法及條件判斷。

二補數減法的基本公式為:

A−B=A+B‾+1A-B=A+\overline{B}+1

其中 B‾\overline{B} 表示將 BB 的每一位元反相。4 位元運算只保留最低 4 位,因此算術結果以模 1616 解讀。

此外,題目規定條件判斷的完整 4 位元輸出必須是:

  • 真:00010001。
  • 假:00000000。

只讓最低位元正確,並不足以符合要求。

解題方法

圖中一般位元與最高位元 ALU 都有輸入反相控制;輸出多工器的 Operation=0,1,2,3\mathrm{Operation}=0,1,2,3 分別選擇 AND、OR、加法器結果與 Less\mathrm{Less}。最高位元 ALU 另外提供 Set\mathrm{Set} 與溢位偵測,供比較運算使用。

先判斷反相後的加法器輸入,再依 Operation\mathrm{Operation} 決定輸出。算術運算可統一寫成:

C=A′+B′+c0(mod16)C=A'+B'+c_0 \pmod{16}

其中

A′={A,Ainvert=0A‾,Ainvert=1,B′={B,Binvert=0B‾,Binvert=1A'= \begin{cases} A,&\mathrm{Ainvert}=0\\ \overline{A},&\mathrm{Ainvert}=1 \end{cases}, \qquad B'= \begin{cases} B,&\mathrm{Binvert}=0\\ \overline{B},&\mathrm{Binvert}=1 \end{cases}

c0c_0 是最低位元的初始進位;其餘位元的進位由前一位元的 CarryOut\mathrm{CarryOut} 傳入。

選項分析

(A) 錯誤:減去額外的 11,只需將初始進位改成 00。

四種運算的設定如下:

運算(Ainvert,Binvert,CarryIn,Operation)(\mathrm{Ainvert},\mathrm{Binvert},\mathrm{CarryIn},\mathrm{Operation})加法器計算
C=A−BC=A-B(0,1,1,2)(0,1,1,2)A+B‾+1A+\overline{B}+1
C=B−AC=B-A(1,0,1,2)(1,0,1,2)A‾+B+1\overline{A}+B+1
C=A−B−1C=A-B-1(0,1,0,2)(0,1,0,2)A+B‾A+\overline{B}
C=B−A−1C=B-A-1(1,0,0,2)(1,0,0,2)A‾+B\overline{A}+B

因為

A+B‾=A−B−1(mod16),A+\overline{B}=A-B-1 \pmod{16},

所以不需要額外的減法器。例如 A=0101A=0101、B=0010B=0010 時,

0101+1101=1 0010,0101+1101=1\,0010,

保留低 4 位得到 00100010,正好是 5−2−1=25-2-1=2。

(B) 正確:以減法產生小於判斷,再由最低位元輸出。

(0,1,1,3)(0,1,1,3) 使內部加法器計算 A−BA-B,但輸出多工器選擇 Less\mathrm{Less}。

🔒

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

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

免費註冊

第 13 題

Considering both DMA (direct memory access) and I/O, which of the following statements are true?

(A) If a machine cannot handle interrupt, the system will not be able to perform I/O via DMA.
(B) By using memory-mapped I/O, CPU employs DMA to release the requirements of keeping busy in I/O movement.
(C) DMA is an I/O processor, which can accept I/O requests from CPU and acts as a slave device on a bus.
(D) The primary problem that DMA will create with a cache memory system is because DMA uses physical addresses whereas CPU caches may use virtual addresses.

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

這一題的完整詳解

核心觀念

DMA(直接記憶體存取)讓 DMA 控制器在 CPU 設定來源位址、目的位址與傳輸長度後,直接在 I/O 裝置與主記憶體間搬移資料。CPU 不必逐筆搬運資料,也不必持續忙等;傳輸完成後,DMA 控制器可以用中斷通知 CPU,但中斷不是 DMA 傳輸成立的必要條件。

判斷各選項時,須分清楚三件事:DMA 與中斷的關係、記憶體映射 I/O 與 DMA 的差異,以及 DMA 存取記憶體時的快取一致性問題。

解題方法

逐項檢查敘述中的因果關係與硬體角色:

  1. 判斷 DMA 是否必須仰賴中斷才能進行資料傳輸。
  2. 分辨記憶體映射 I/O 解決的是 CPU 如何存取控制暫存器,DMA 解決的是資料如何搬移。
  3. 確認 DMA 控制器在匯流排傳輸時是主控端還是從屬端。
  4. 比較 DMA 寫入主記憶體後,快取中的資料是否仍與主記憶體一致。

選項分析

(A) 錯誤。
DMA 傳輸不要求系統一定具備中斷處理能力。CPU 可設定 DMA 控制器啟動傳輸,之後以輪詢方式檢查控制器的狀態暫存器,確認傳輸是否完成。中斷只是讓 DMA 控制器能在完成時主動通知 CPU,避免 CPU 持續輪詢。

🔒

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

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

免費註冊
📄 以下 2 題共用同一段題幹

The following text is excerpted from an article on the web about CPU performance.

“The total clock speed or CPU performance of a device indicates how many processing cycles per second can be executed by a CPU, considering all of its processing units (more commonly referred to as cores). The CPU speed is measured in gigahertz (GHz), with each gigahertz being equivalent to one thousand million cycles per second. Given the same clock rate, more CPU parallelism can contribute better performance. However, power dissipation and circuit temperature usually constrain modern processors clock frequency and thus they can be dynamically changed so that circuit temperature stays below a certain limit.

When considering the total CPU speed, let us look for more GHz and a higher core count. Although this is not the single determining factor for an electronic device's performance, high processor speed is crucial if you are looking to perform demanding tasks such as gaming or video editing. As for the core count, a CPU chip with multiple processing units has the advantage of being able to run various tasks at the same time.

Nowadays, a CPU chip can comprise cores with varying speeds, thanks to ARM's big.LITTLE technology; the advantage is that tasks are assigned to different cores depending on how demanding they are, optimizing system usage, and preventing overheating. For instance, sending e-mails doesn't require much processing power. Instead of assigning this task to a sophisticated core, the system will delegate these tasks to LITTLE cores that produce less heat than the BIG cores with an aggressive execution such as multi-issue pipelines, hardware multithreading or out-of-order execution. Besides, even a single-core may be able to operate on different clock speeds: namely “base” and “turbo.”

The current victor when it comes to total clock speed for computers is AMD's Epyc 7742, flaunting an overall clock rate of 64×2.2564\times2.25 GHz (64 cores with 2.25 GHz each). The fierce competition among manufacturers means that higher CPU performance is a never-ending race.”

第 14 題

For CPU clock rate, which of the following statements are true?

(A) Executing programs on a 1.5 GHz CPU could be faster than on another CPU of 2 GHz even within the same brand.
(B) Powerful branch prediction is essential for CPU with a high clock rate so as to minimize the penalty due to branch hazard.
(C) Given that the big.LITTLE consisting of two cores, one big core can run at 4 GHz and the LITTLE core runs at 2 GHz. The average clock speed will be 3 GHz.
(D) Unbalance of pipeline stages affects cycle time (thus clock rate). We can push more clock rate by adding more stages and thus improve the CPU throughput without increasing the instruction latency.

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

這一題的完整詳解

核心觀念

CPU 時脈率表示每秒可執行的時脈週期數,時脈率越高,單一週期越短:

Tcycle=1fT_{\text{cycle}}=\frac{1}{f}

但程式執行速度還取決於指令數、每指令平均週期數(CPI)、處理器架構與平行度。常用的 CPU 執行時間公式是:

TCPU=指令數×CPI時脈率T_{\text{CPU}}=\frac{\text{指令數}\times\text{CPI}}{\text{時脈率}}

因此,不能只比較 GHz,就判定哪顆 CPU 一定較快。管線化則是把指令執行工作分成多個階段;階段延遲不均會由最慢的階段限制時脈週期。增加管線階段可以提高理想吞吐量,但通常會增加單一指令通過管線所需的階段數與延遲。

解題方法

逐項檢查選項中的主張:

  1. 比較不同 CPU 的執行速度時,確認是否只看時脈率,或也考慮 CPI 與架構差異。
  2. 判斷高時脈設計中的分支預測,是否能降低分支冒險造成的停滯或管線清空成本。
  3. 對 big.LITTLE 的兩個核心頻率,依題目所問計算算術平均;同時注意平均頻率不等於實際效能。
  4. 分清管線化的「吞吐量」與「單一指令延遲」:兩者不是同一個指標。

選項分析

(A) 正確。
時脈率較低的 1.5 GHz CPU,仍可能比 2 GHz CPU 執行程式更快。由

TCPU=指令數×CPI時脈率T_{\text{CPU}}=\frac{\text{指令數}\times\text{CPI}}{\text{時脈率}}

可知,即使 1.5 GHz 較低,只要它的 CPI 更小、執行程式所需指令更少,或微架構效率更高,總執行時間就可能較短。

🔒

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

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

免費註冊

第 15 題

Considering CPUs with full parallelism, which of the following statements are true?

(A) To fully utilize AMD 64-core CPUs, the software has to exploit full parallelism by both multiprocessing and multithreading.
(B) In big.LITTLE technology, the Little cores will keep pipeline as deep as possible to achieve higher clock rate, more focused on ILP (instruction level parallelism). In contrast, big cores usually embed TLP (task level parallelism) such as to maintain a low clock rate.
(C) With two clock rates in a core, the base clock time is determined by the longest stage of the pipeline and the turbo mode is limited by the maximum clock generator at run time.
(D) CPU parallelism can be obtained by multi-issue, SIMD, MIMD, and vector techniques. The multi-issue, SIMD, and vector need compiler optimization, whereas MIMD needs supports from OS.

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

這一題的完整詳解

核心觀念

本題考查 CPU 平行處理的層次與方式,以及時脈週期、管線和動態升頻的關係。

  • 多核心平行:多個核心可同時執行不同工作;程式必須有足夠的可平行工作,核心才有工作可做。
  • 多重發出(multi-issue):處理器在一個時脈週期內發出多條指令,以利用指令層級平行(ILP)。
  • SIMD 與向量處理:同一條指令同時處理多筆資料,利用資料平行。
  • MIMD:多個處理單元各自執行不同指令流,常由作業系統管理工作與處理器的配置。
  • 管線時脈:時脈週期至少要涵蓋管線中最慢級的延遲。動態升頻則還受功耗、溫度與處理器可用頻率範圍限制。

解題方法

先分辨各選項描述的平行層次:A、B 談多核心與 big.LITTLE;C 談管線時脈和升頻;D 談指令、資料及多處理器平行。再檢查每個選項是否把必要條件說得過度絕對,或混淆不同平行方式。

選項分析

(A) 錯誤。
要充分利用 64 核心,軟體須提供足夠的可平行工作,但不必同時採用多處理(multiprocessing)與多執行緒(multithreading)。使用多程序或多執行緒等方式,都能安排工作在多核心上執行;真正的條件是工作能被拆分並有效分配。

(B) 錯誤。
此選項把 big.LITTLE 的特性對調。

🔒

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

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

免費註冊

第 16 題

The single-precision (32-bit) IEEE 754 floating-point format is as follows. Which of the following statements are correct?

🖼️【此處有附圖,見下方】

(A) To represent 3.125 in the IEEE 754 format, the exponent part is 00000001b.
(B) To represent 3.125 in the IEEE 754 format, the fraction part is 480000h.
(C) 1.1012×2−1301.101_2\times2^{-130} cannot be represented using the IEEE 754 format.
(D) To represent 1.1012×2−1301.101_2\times2^{-130} in the IEEE 754 format, the exponent part is 00000000b.

🖼️ 本題附圖:
第 16 題附圖

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

這一題的完整詳解

核心觀念

IEEE 754 單精度浮點數由 1 位符號位元、8 位指數欄位與 23 位小數欄位組成。正規化數的實際指數為「指數欄位的無號值減去偏移量 127」;指數欄位全為 0 時,非零小數欄位表示非正規化數,其數值為 (−1)s×0.f×2−126(-1)^s \times 0.f \times 2^{-126}。

解題方法

圖中格式標示符號位元、8 位指數與 23 位小數;表格也列出指數為 0、小數非零時代表非正規化數。先將 3.1253.125 轉成二進位,檢查指數與小數欄位;再判斷 1.1012×2−1301.101_2 \times 2^{-130} 是否能以非正規化數表示。

3.12510=11.0012=1.10012×213.125_{10}=11.001_2=1.1001_2 \times 2^1

指數欄位應為 1+127=128=1000000021+127=128=10000000_2;小數欄位取隱含首位 11 之後的位元,為 10011001,再補零至 23 位,即 100100000000000000000002=480000h10010000000000000000000_2=480000_h。

對於 1.1012×2−1301.101_2 \times 2^{-130},正規化指數 −130-130 小於最小正規化指數 −126-126,但可用非正規化數表示。依非正規化數公式:

0.f×2−126=1.1012×2−1300.f \times 2^{-126}=1.101_2 \times 2^{-130}
🔒

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

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

免費註冊

第 17 題

Consider a five-stage pipelined MIPS CPU. Please select the signals that are required to insert a stall cycle when data hazard is detected at ID stage.

(A) Set IF.Flush = 1 (to clear IF/ID).
(B) Set PCWrite = 0 (to disable the write to Program Counter (PC)).
(C) Set IF/IDWrite = 0 (to disable the write to IF/ID).
(D) Set ID.Flush = 1 (to set 9 control signals used in EX, MEM and WB stages to 0).

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

這一題的完整詳解

核心觀念

這題考五階段 MIPS 管線在 ID 階段偵測到資料危障時,如何插入一個停滯週期。停滯的目的有兩個:

  1. 暫停前端,讓目前尚未能往下執行的指令留在 IF/ID 暫存器中。
  2. 在後續管線中插入一個 bubble,避免危障指令產生錯誤的暫存器或記憶體副作用。

因此,PC 與 IF/ID 暫存器必須停止更新;同時,送往 EX、MEM、WB 階段的控制訊號必須清為 0。

解題方法

依照「保留目前指令、停止取新指令、注入 bubble」三個效果判斷:

  • 保留目前指令:禁止寫入 IF/ID,令 IF/IDWrite = 0。
  • 停止 PC 前進:禁止更新 PC,令 PCWrite = 0。
  • 注入 bubble:將該指令的管線控制訊號清為 0,令 ID.Flush = 1。

這樣目前指令會留在 IF/ID 中,PC 也不會前進,而控制訊號清零後,進入後續階段的效果等同於一條不會改變處理器狀態的空操作。

選項分析

🔒

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

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

免費註冊

第 18 題

Given the pipelined CPU in the figure below, which code sequence(s) will fail to run correctly if the data-path A is cut?

🖼️【此處有附圖,見下方】

(A)

add $s1, $t0, $t1
add $s3, $s2, $s1
add $s2, $s3, $s1

(B)

add $s3, $t0, $t1
add $s1, $s2, $s1
add $s2, $s3, $s1

(C)

add $s1, $t0, $t1
add $s1, $s2, $s1
add $s2, $s3, $s1

(D)

add $s1, $t0, $t1
add $s2, $s2, $s1
add $s2, $s3, $s1
🖼️ 本題附圖:
第 18 題附圖

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

這一題的完整詳解

核心觀念

本題考五級 MIPS 管線的資料相依與資料轉送(forwarding)。五個階段為 IF、ID、EX、MEM、WB;add 在 EX 階段算出結果,但直到 WB 階段才寫回暫存器,因此後續指令若提早使用該結果,就必須靠轉送取得正確資料。

對指令 add rd, rs, rt 而言,rs 是 ALU 第一運算元,rt 是第二運算元。連續三條指令的相依關係可依距離判斷:

  • 前一條指令的結果:由 EX/MEM 轉送。
  • 前兩條指令的結果:由 MEM/WB 轉送。
  • 若兩條先前指令都寫入同一暫存器,必須優先使用 EX/MEM 中較新的結果。

解題方法

圖中的 A 是 MEM/WB 回傳至 ALU 第二運算元(rt)轉送多工器的支線。切斷 A 後,EX/MEM 到第二運算元的轉送仍可使用,MEM/WB 到第一運算元(rs)的轉送也仍可使用。

將每組指令依序記為 I1,I2,I3I_1,I_2,I_3。沒有停頓時,管線時序如下:

指令第 1 週期第 2 週期第 3 週期第 4 週期第 5 週期
I1I_1IFIDEXMEMWB
I2I_2IFIDEXMEM
I3I_3IFIDEX

因此:

  • 第 4 週期,I2I_2 使用 I1I_1 的結果時,走 EX/MEM 轉送。
  • 第 5 週期,I3I_3 使用 I2I_2 的結果時,走 EX/MEM 轉送;使用 I1I_1 的結果時,走 MEM/WB 轉送。

判斷重點就是:**第三條指令的 rt 是否必須使用第一條指令的結果。**若必須,就會用到已切斷的 A。

選項分析

(A) 會執行錯誤,應選。

add $s1, $t0, $t1
add $s3, $s2, $s1
add $s2, $s3, $s1
  • I2I_2 的 rt = $s1 使用 I1I_1 的結果,透過 EX/MEM 轉送,正常。
  • I3I_3 的 rs = $s3 使用 I2I_2 的結果,透過 EX/MEM 轉送,正常。
  • I3I_3 的 rt = $s1 使用 I1I_1 的結果,必須透過 MEM/WB 的 A 支線。

A 被切斷後,第三條指令無法取得更新後的 `

🔒

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

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

免費註冊

第 19 題

For a MIPS 5-stage pipelined CPU with data forwarding and stall mechanisms implemented, which of the following statements are true for the code sequence below? You may refer to the following code sequence and the CPU pipeline figure.

🖼️【此處有附圖,見下方】

add  $s2, $s2, $s3
lw   $s1, 0($s2)
addi $t1, $s2, 8
sw   $t2, 0($s1)
lw   $t3, 0($s1)
add  $s3, $t3, $s2
sub  $s3, $s3, $s2

(A) It takes 12 clock cycles to finish the execution of the code sequence.
(B) There are total 2 stall cycles when running the code sequence.
(C) The instruction in EXE stage is addi when the code runs to the 5th cycle.
(D) The ALUSrc signal is set to 0 when the code runs to the 5th cycle.

🖼️ 本題附圖:
第 19 題附圖

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

這一題的完整詳解

核心觀念

五階段 MIPS 管線依序為 IF(取指)、ID(解碼/讀暫存器)、EX(執行)、MEM(存取資料記憶體)與 WB(寫回)。資料轉送可處理多數相鄰指令的資料相依;但 lw 載入的資料要到 MEM 階段末才取得,若下一個指令立刻在 EX 使用該資料,仍須停一個時脈週期。

解題方法

原卷圖示為具備資料轉送與停滯機制的五階段 MIPS 管線。依序檢查指令間的讀寫相依,並將停滯插入管線時序;總執行週期數為指令數加管線填滿與排空所需的 44 個週期,再加上停滯週期。

令七條指令依序為 I1I_1 至 I7I_7。I2I_2 的 lw 載入 $s1,而 I4I_4 的 sw 使用 $s1 作為位址基底;中間隔著 I3I_3,因此 $s1 可透過轉送提供給 I4I_4,不需停滯。I5I_5 載入 $t3,緊接的 I6I_6 在 EX 階段使用 $t3,形成 lw 後立即使用的相依,因此停一個週期。

指令123456789101112
I1I_1 addIFIDEXMEMWB
I2I_2 lwIFIDEXMEMWB
I3I_3 addiIFIDEXMEMWB
$I_4
🔒

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

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

免費註冊

第 20 題

For the MIPS assembly code sequence below, assume that s2s_2 and t1t_1 are initialized to 00 and 33, respectively. Which of the following statements are correct for the execution of this code sequence?

🖼️【此處有附圖,見下方】

Loop:   addi $t2, $zero, 0x6
Loop2:  addi $s2, $s2, 1
        addi $t2, $t2, -1
        bne  $t2, $zero, Loop2  // branch1
        addi $t1, $t1, -1
        bne  $t1, $zero, Loop   // branch2
Done:

(A) Assume a 1-bit predictor is used and the predictor is initialized as taken. For the inner bne\mathrm{bne} (marked as branch1), the rate of prediction accuracy is 2/32/3.
(B) Assume a 2-bit predictor is used and the predictor is initialized as taken. For the inner bne\mathrm{bne} (marked as branch1), the rate of prediction accuracy is 5/65/6.
(C) Assume a 1-bit predictor is used and the predictor is initialized as taken. For the outer bne\mathrm{bne} (marked as branch2), the rate of prediction accuracy is 1/31/3.
(D) Assume the predictors are initialized as taken. For the outer bne\mathrm{bne} (marked as branch2), a 2-bit predictor has higher accuracy rate than a 1-bit predictor.

🖼️ 本題附圖:
第 20 題附圖

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

這一題的完整詳解

核心觀念

本題考分支預測器如何依據「歷史結果」預測下一次分支,以及迴圈進出時的預測錯誤。以 TT 表示跳躍(taken),NN 表示不跳躍(not taken)。

  • 1-bit 預測器:預測結果等於上一次的實際結果;每次分支執行後更新狀態。
  • 2-bit 飽和計數器:有強跳躍、弱跳躍、弱不跳躍、強不跳躍四個狀態。實際結果為 TT 時往強跳躍方向移動一格,為 NN 時往強不跳躍方向移動一格;到端點後不再移動。處於強跳躍時,單次 NN 只會使狀態變成弱跳躍,下一次仍預測 TT。

準確率的計算式為:

預測準確率=預測正確次數分支實際執行次數\text{預測準確率} =\frac{\text{預測正確次數}}{\text{分支實際執行次數}}

以下依一般題目設定,各分支保有自己的預測狀態,且迴圈重啟時不會重設預測器。

解題方法

原卷程式在 Loop 將 $t2 設為 0x6,內層每次將 $t2 減 11,由 branch1 判斷是否繼續。離開內層後才將 $t1 減 11,由 branch2 判斷是否回到 Loop;初始 $t1 為 33。

1. 列出兩個分支的實際結果

每次進入內層,branch1 判斷時 $t2 依序為:

5, 4, 3, 2, 1, 05,\ 4,\ 3,\ 2,\ 1,\ 0

因此每輪內層的結果是 TTTTTNTTTTTN。外層共執行 33 輪,所以 branch1 的完整結果為:

TTTTTN⏟第 1 輪TTTTTN⏟第 2 輪TTTTTN⏟第 3 輪\underbrace{TTTTTN}_{\text{第 1 輪}} \quad \underbrace{TTTTTN}_{\text{第 2 輪}} \quad \underbrace{TTTTTN}_{\text{第 3 輪}}

branch1 共執行 1818 次。branch2 判斷時 $t1 依序為 2,1,02,1,0,因此只執行 33 次,结果為:

TTNTTN

2. 計算 branch1 的準確率

對 1-bit 預測器,初始預測為 TT:

內層輪次開始時預測預測錯誤的位置正確次數
第 1 輪TT最後一次 NN55
第 2 輪NN第一次 TT、最後一次 NN44
第 3 輪NN第一次 TT、最後一次 NN44
🔒

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

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

免費註冊
📄 以下 4 題共用同一段題幹

Consider using semaphores for the first readers-writers problem, which allows either one writer or at most nn readers in the critical section at the same time (no reader is kept waiting unless a writer has already obtained permission to use the shared object). We use an integer read_countread\_count to count the number of readers that are currently reading the data. We use two binary semaphores: rw_mutexrw\_mutex and mutexmutex. The former is common to both reader and writer processes. The mutexmutex semaphore is used to ensure mutual exclusion when the variable read_countread\_count is updated. The reader’s code is shown below.

sem_wait(&①);
read_count++;
if (read_count == ②)
    sem_wait(&③);
sem_post(&④);

/* read the data */

sem_wait(&⑤);
read_count--;
if (read_count == ⑥)
    sem_post(&⑦);
sem_post(&⑧);

第 21 題

What is the initial value of mutexmutex?

(A) 0
(B) 1
(C) nn
(D) None of the above.

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

這一題的完整詳解

核心觀念

mutex 是用來保護共享變數 read_count 的二元 semaphore,確保同一時間只有一個讀者能更新它。二元 semaphore 的初始值設為 11,表示一開始沒有程序占用這把鎖,第一個執行 sem_wait(&mutex) 的程序可以進入臨界區。

解題方法

讀者進入時,先對 mutex 執行 sem_wait,再增加 read_count;離開時也先取得 mutex,再減少 read_count。因此,mutex 必須允許第一個讀者一開始就能取得,初值為 11。

若初值為 00,第一個執行 sem_wait(&mutex) 的讀者會立即阻塞,無法更新 read_count。

選項分析

🔒

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

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

免費註冊

第 22 題

What should be in ①?

(A) mutexmutex
(B) rw_mutexrw\_mutex
(C) read_countread\_count
(D) nn

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

這一題的完整詳解

核心觀念

這題考讀者優先(first readers-writers)同步機制中,兩個 semaphore 的分工:

  • mutex:保護 read_count,避免多個讀者同時更新計數而發生競爭。
  • rw_mutex:控制共享資料的存取權。寫者進入時必須取得它;第一位讀者也會取得它,阻止寫者在讀者讀取期間進入。

解題方法

讀者進入時,必須先取得保護計數器的 semaphore,才能安全地增加 read_count 並檢查自己是否為第一位讀者:

sem_wait(&mutex);
read_count++;
if (read_count == 1)
    sem_wait(&rw_mutex);
sem_post(&mutex);
🔒

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

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

免費註冊

第 23 題

What should be in ②?

(A) 0
(B) 1
(C) nn
(D) None of the above.

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

這一題的完整詳解

核心觀念

這題考讀者-寫者問題中,如何用 read_count 判斷「第一位讀者」進入臨界區。read_count 計算目前正在讀取資料的讀者數;rw_mutex 則用來讓讀者群與寫者互斥。

解題方法

讀者先以 mutex 保護 read_count,再將計數加一。只有第一位讀者需要取得 rw_mutex,阻擋寫者進入;後續讀者可在第一位讀者已取得 rw_mutex 的情況下進入。因此判斷條件是:

read_count=1read\_count = 1

讀者離開時,最後一位讀者將 read_count 減至 0,並釋放 rw_mutex,讓寫者有機會進入。

題幹提到最多 nn 位讀者同時讀取,但這段程式碼沒有以計數信號量限制讀者人數;不過這不影響 ② 的判斷,因為 ② 用來辨認第一位讀者,應填 1。

🔒

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

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

免費註冊

第 24 題

What should be in ⑦?

(A) mutexmutex
(B) rw_mutexrw\_mutex
(C) read_countread\_count
(D) nn

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

這一題的完整詳解

核心觀念

讀者優先的讀者—寫者問題中,rw_mutex 用來保護共享資料:讀者進入時,第一位讀者取得它;讀者離開時,最後一位讀者釋放它。如此一來,多位讀者可同時讀取,但寫者必須等到所有讀者離開後才能進入。

mutex 則只用來保護 read_count,避免多個讀者同時更新計數器。這兩個信號量用途不同,不能混用。

解題方法

讀者離開時,先取得 mutex,再將 read_count 減一。當計數變為 00,代表目前沒有讀者仍在讀取,這時必須釋放 rw_mutex,讓等待中的寫者有機會進入。

因此,⑦ 應填入 rw_mutex。相關程式片段為:

sem_wait(&mutex);
read_count--;
if (read_count == 0)
    sem_post(&rw_mutex);
sem_post(&mutex);

選項分析

🔒

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

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

免費註冊
📄 以下 4 題共用同一段題幹

Compare Oracle SPARC and ARM in supporting the page table. The former adopts 2-level caching and a hashed table with the feature of span (the number of pages an entry represents), while the latter uses also 2-level caching and a hybrid 1/2-level hierarchical page table (1-level for big pages and 2-level for small pages). Suppose 100 ns for memory access, 10 ns for 2nd cache access with cache hit ratio of 90%, and 1 ns for 1st cache access with cache hit ratio of 60%. The remaining 10% is for table lookup in the memory. Note that the 1st cache is looked up first before the 2nd cache, and then the table in the memory.

第 25 題

What is the minimum access time for a desired word in a frame?

(A) 11 ns
(B) 101 ns
(C) 111 ns
(D) 201 ns

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

這一題的完整詳解

核心觀念

第一層與第二層快取用來查詢頁表項目,以取得頁框位置;查到頁框後,仍須存取記憶體,才能讀取題目指定的字。因此,最短存取時間是「最快取得頁表項目的時間」加上「讀取目標字的時間」。

解題方法

最快的情況是第一層快取命中。此時只需花 1 ns1\text{ ns} 查得頁框,再花 100 ns100\text{ ns} 從記憶體讀取目標字:

1+100=101 ns1 + 100 = 101\text{ ns}

題目給的命中率會影響平均存取時間,但不影響「最小」存取時間。

選項分析

  • (A) 11 ns:錯誤。 這是第一層與第二層快取存取時間相加,沒有計入取得頁框後讀取目標字所需的 100 ns100\text{ ns}。
🔒

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

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

免費註冊

第 26 題

In ARM, what is the maximum access time for a desired word in a frame?

(A) 201 ns
(B) 211 ns
(C) 311 ns
(D) 411 ns

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

這一題的完整詳解

核心觀念

這題考查頁表查詢與資料存取的總延遲。存取目標字之前,系統必須先完成頁表查詢,取得實體頁框位置,再讀取目標字。

ARM 的混合式頁表中,大頁使用一級頁表,小頁使用二級頁表。題目問「最大」存取時間,因此採用較慢的小頁路徑,也就是二級頁表查詢。

解題方法

查詢依序經過第一層快取、第二層快取,再查詢記憶體中的頁表。求最大時間時,兩層快取皆未命中,因此兩層快取的查詢時間都要計入。

二級頁表需要讀取兩次記憶體中的頁表項目;取得實體位址後,還要再讀取一次記憶體,取得目標字。總時間為:

1+10+2×100+100=311 ns1 + 10 + 2 \times 100 + 100 = 311\text{ ns}

其中 11 ns 與 1010 ns 是兩層快取查詢時間,兩次 100100 ns 是二級頁表查詢,最後的 100100 ns 是讀取目標字。

🔒

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

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

免費註冊

第 27 題

In SPARC, if the maximum length of a linked list entry is 4, what is the maximum access time for a desired word in a frame?

(A) 301 ns
(B) 501 ns
(C) 611 ns
(D) 811 ns

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

這一題的完整詳解

核心觀念

SPARC 用雜湊頁表:虛擬頁號經雜湊函數算出表格槽位,槽位指向一條鏈結串列,串列中每個節點存(虛擬頁號、頁框號、下一個節點的指標)。查找時要先讀雜湊表的槽位,再沿串列逐一比對虛擬頁號。

題目給的路徑依序是:第一層快取 11 ns → 第二層快取 1010 ns → 記憶體中的頁表(每次存取 100100 ns)→ 讀目標字 100100 ns。

解題方法

最大存取時間發生在:兩層快取都沒中,而且要找的項目在串列的最後一個(第 4 個)節點。

  • 快取查找:1+10=111+10=11 ns
  • 讀雜湊表槽位取得串列開頭:11 次記憶體存取
  • 沿串列走到第 4 個節點:44 次記憶體存取
  • 讀目標字:11 次記憶體存取
11+(1+4)×100+100=611 ns11+(1+4)\times100+100=611\text{ ns}

選項分析

🔒

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

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

免費註冊

第 28 題

In ARM, for a large process using big pages, what is the average access time for a desired word in a frame?

(A) 33 ns
(B) 60 ns
(C) 115 ns
(D) 215 ns

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

這一題的完整詳解

核心觀念

這題考多層頁表快取的平均存取時間。讀取目標字之前,必須先取得頁框位址;完成位址轉換後,還要再存取一次記憶體,才能讀到目標字。

ARM 的大頁面使用一層頁表,因此頁表未命中時,頁表查找需要一次記憶體存取,耗時 100100 ns。目標字本身的記憶體存取也需 100100 ns。

解題方法

依題意將結果分成三種情況:

題目說明查找是依序進行的:先查第一層快取,沒中才查第二層,再沒中才到記憶體查頁表。所以每一種情況都要把前面查過的時間加上去:

  • 第一層快取命中(60%60\%):11 ns。
  • 第一層沒中、第二層命中(累計命中率 90%90\%,額外 30%30\%):1+10=111+10=11 ns。
  • 兩層都沒中(剩餘 10%10\%),查一層頁表:1+10+100=1111+10+100=111 ns。

位址轉換的平均時間:

0.6(1)+0.3(11)+0.1(111)=0.6+3.3+11.1=15 ns0.6(1)+0.3(11)+0.1(111)=0.6+3.3+11.1=15\text{ ns}
🔒

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

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

免費註冊
📄 以下 4 題共用同一段題幹

You have designed a brand new CPU: NYCU (New Younker Compute Unit). We know:

real CPI=ideal CPI+data access prob×avg stall cycles\mathrm{real\ CPI}=\mathrm{ideal\ CPI}+\mathrm{data\ access\ prob}\times\mathrm{avg\ stall\ cycles}

avg stall=miss rate×miss penalty\mathrm{avg\ stall}=\mathrm{miss\ rate}\times\mathrm{miss\ penalty}

Assume that NYCU can run at 2 GHz and its lw/sw\mathrm{lw}/\mathrm{sw} share is 25% of total NN instructions. Let us ignore the instruction cache issue and ideal CPI is 1. The access time of main memory is 100 ns.

第 29 題

We build a direct-mapped L1 data cache to match the NYCU1 pipeline. Assume that the miss rate is 4% for each cache access. What is the real CPI of NYCU1?

(A) 2
(B) 3
(C) 4
(D) 5

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

這一題的完整詳解

核心觀念

實際 CPI 由理想 CPI 加上資料存取造成的平均停滯週期計算:

real CPI=ideal CPI+data access prob×avg stall cycles\mathrm{real\ CPI} = \mathrm{ideal\ CPI} + \mathrm{data\ access\ prob} \times \mathrm{avg\ stall\ cycles}

每次資料存取的平均停滯週期為:

avg stall=miss rate×miss penalty\mathrm{avg\ stall} = \mathrm{miss\ rate} \times \mathrm{miss\ penalty}

主記憶體存取時間為 100 ns;快取未命中時,需等待主記憶體完成存取,因此以 100 ns 作為未命中懲罰時間。

解題方法

NYCU 的時脈為 2 GHz,因此一個時脈週期的時間是:

Tcycle=12 GHz=0.5 nsT_{\mathrm{cycle}}=\frac{1}{2\ \mathrm{GHz}}=0.5\ \mathrm{ns}

將主記憶體存取時間換算成時脈週期:

🔒

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

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

免費註冊

第 30 題

Now we build a 4-way set-associative L1 data cache for the new NYCU2 pipeline. Which of the following effects is NOT true for the new L1 compared to NYCU1?

(A) The CPU clock rate could be reduced.
(B) Better access time since address tags can be compared in parallel.
(C) An extra multiplexer to select blocks.
(D) Conflict cache misses can be reduced.

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

這一題的完整詳解

核心觀念

本題考查組相連快取的查找流程,以及它相對於直接對映快取在命中時間與衝突失誤上的取捨。以下依 NYCU1 採用直接對映 L1 快取來比較。

4-way set-associative 快取中,每個索引位置對應一個集合,集合內有 4 個快取區塊。查找時,硬體會同時比較 4 個標籤,再依命中的 way 選出對應資料。

解題方法

比較 4-way 組相連快取和直接對映快取的硬體與效能影響:

  • 同一集合有 4 個候選區塊,須進行多路標籤比較,並增加選擇資料的多工器。
  • 多個標籤可平行比較,因此不用依序搜尋 4 個 way;但增加的比較與資料選擇電路會使快取命中路徑較複雜,存取時間不會因此優於直接對映快取。
  • 同一集合可容納多個記憶體區塊,因此衝突失誤會減少。

因此,題目將「標籤可平行比較」直接推論成「存取時間更好」,是錯誤的;平行比較避免了序列搜尋,卻不能消除額外比較器與多工器造成的延遲。

選項分析

(A) The CPU clock rate could be reduced.

正確。組相連快取需要標籤比較與資料選擇電路,可能拉長快取存取的關鍵路徑。若處理器時脈週期必須涵蓋這段延遲,時脈頻率就可能降低。

🔒

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

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

免費註冊

第 31 題

Now we design an NYCU3 by providing a 128 KB L2 to NYCU1, where L2 has a hit time of 8 ns and a miss rate of 20%. What is the real CPI of NYCU3?

(A) 0.28
(B) 0.56
(C) 1.28
(D) 1.56

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

這一題的完整詳解

核心觀念

加上 L2 之後,L1 未命中的代價不再是整趟主記憶體,而是「先查 L2;L2 也沒中才去主記憶體」:

L1 miss penalty=L2 hit time+L2 miss rate×memory access time\text{L1 miss penalty}=\text{L2 hit time}+\text{L2 miss rate}\times\text{memory access time}

所有時間都要先換成時脈週期:2 GHz 的週期是 0.50.5 ns。

解題方法

  1. 換算週期:L2 命中時間 8 ns=168\text{ ns}=16 週期;主記憶體 100 ns=200100\text{ ns}=200 週期。
  2. L1 未命中代價:16+0.2×200=16+40=5616+0.2\times200=16+40=56 週期。
  3. 每次資料存取的平均停滯:0.04×56=2.240.04\times56=2.24 週期。
  4. 只有 25%25\% 的指令是 lw/sw:
🔒

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

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

免費註冊

第 32 題

We have to consider TLB in accessing for the NYCU memory hierarchy. Which of the following statements is NOT true for TLB?

(A) TLB = translation-lookaside buffer.
(B) TLB miss will result into a page fault.
(C) Small TLB uses fully-associative.
(D) TLB is accessed before L1 (physical address).

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

這一題的完整詳解

核心觀念

TLB(translation-lookaside buffer,快取式位址轉譯緩衝器)保存近期使用的虛擬位址到實體位址的轉譯結果。處理器存取記憶體時,先查詢 TLB;若命中,就能快速取得實體位址。若 TLB 未命中,硬體或作業系統會查詢頁表,再依頁表結果處理。

TLB miss 與 page fault 是不同事件:

  • TLB miss:TLB 中沒有該虛擬頁的轉譯資料,仍須查頁表。
  • Page fault:頁表指出該虛擬頁目前不在主記憶體,需由作業系統處理,通常要從磁碟載入頁面。

因此,TLB miss 不必然造成 page fault。

解題方法

逐一核對選項所描述的定義、快取組織方式與位址轉譯順序。判斷關鍵在於區分「TLB 沒有轉譯資料」與「頁面不在主記憶體」:前者是 TLB miss,後者才是 page fault。

選項分析

(A) TLB = translation-lookaside buffer.

正確。TLB 的全名是 translation-lookaside buffer,用來快取虛擬位址至實體位址的轉譯結果。

🔒

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

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

免費註冊
📄 以下 3 題共用同一段題幹

Given the MIPS code sequence below, assume it starts at location 8800 4000h8800\ 4000_{\mathrm{h}} in memory.

        add $t0, $zero, $zero
loop:   beq $s2, $zero, finish
        add $t0, $t0, $s1
        sub $s2, $s2, 1
        j loop
finish: sll $t0, $t0, 2
        add $v0, $t0, $zero

第 33 題

Assume the register number of s2s2 is 18 and the OP code of beq\mathrm{beq} is 4. The MIPS machine code of the beq\mathrm{beq} in this code sequence is:

(A) 0x12400003
(B) 0x12400004
(C) 0x12400000
(D) 0x12400100

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

這一題的完整詳解

核心觀念

beq 使用 MIPS 的 I 型格式:

opcode6  ∣  rs5  ∣  rt5  ∣  immediate16\text{opcode}_{6} \;|\; \text{rs}_{5} \;|\; \text{rt}_{5} \;|\; \text{immediate}_{16}

分支指令的位移量以「字」為單位,且相對於 PC + 4 計算:

immediate=目標位址−(PC+4)4\text{immediate} = \frac{\text{目標位址}-(PC+4)}{4}

解題方法

每條 MIPS 指令占 4 個位元組。由起始位址 0x880040000x88004000 依序列出指令位址:

指令位址
add $t0, $zero, $zero0x880040000x88004000
beq $s2, $zero, finish0x880040040x88004004
add $t0, $t0, $s10x880040080x88004008
sub $s2, $s2, 10x8800400C0x8800400C
j loop0x880040100x88004010
finish: sll $t0, $t0, 20x880040140x88004014

beq 的 PC 是 0x880040040x88004004,因此分支基準位址為 PC+4=0x88004008PC+4=0x88004008。目標標籤 finish 位於 0x880040140x88004014:

🔒

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

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

免費註冊

第 34 題

The MIPS machine code of the j\mathrm{j} (OP code is 2) in this code sequence is:

(A) 0x08001001
(B) 0x22001001
(C) 0x0A001001
(D) 0x02001001

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

這一題的完整詳解

核心觀念

MIPS 的 j 是 J 型指令,機器碼由 6 位元 opcode 與 26 位元目標欄位組成:

instruction=(opcode≪26)  ∣  target\text{instruction} = (\text{opcode} \ll 26) \;|\; \text{target}

j 的 opcode 為 22。目標欄位不是完整位址,而是目標位址的 [27:2][27:2] 位元;執行時再接上 PC+4 的高 4 位元,並在低 2 位補零:

jump 位址={(PC+4)31:28, target25:0, 00}\text{jump 位址} = \{(PC+4)_{31:28},\ \text{target}_{25:0},\ 00\}

解題方法

每條 MIPS 指令占 44 bytes。以程式起始位址 0x880040000x88004000 編號:

指令位址
add $t0, $zero, $zero0x880040000x88004000
beq $s2, $zero, finish0x880040040x88004004
add $t0, $t0, $s10x880040080x88004008
sub $s2, $s2, 10x8800400C0x8800400C
j loop0x880040100x88004010

loop 標籤位於 beq,所以跳躍目標是 0x880040040x88004004。J 型指令的 26 位元目標欄位為:

🔒

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

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

免費註冊

第 35 題

Assume both s1s1 and s2s2 initially contain integers 5 and 6, respectively. What is the value that v0v0 will contain after the execution of the whole code sequence?

(A) 6
(B) 30
(C) 60
(D) 120

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

這一題的完整詳解

核心觀念

這段 MIPS 程式是一個「計數迴圈」:每輪把 $s1 累加到 $t0、把 $s2 減 1,直到 $s2 變成 0 才離開;最後 sll $t0, $t0, 2 左移 2 位,等於乘以 22=42^2=4,結果再複製到 $v0。

等價的高階寫法:

t0 = 0
while s2 != 0:
    t0 = t0 + s1
    s2 = s2 - 1
v0 = t0 * 4

解題方法

初始時 $s1 為 55、$s2 為 66。

  1. add $t0, $zero, $zero:$t0 設為 00。
  2. 迴圈:$s2 從 66 遞減到 00,共執行 66 輪,每輪 $t0 加 55,結束時 $t0 為 6×5=306\times5=30。
🔒

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

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

免費註冊

其他考古題