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

第 1 題

For different directory structures, which of the following statements are true?

(A) A tree-structured directory prohibits the sharing of files or subdirectories by symbolic links.
(B) General graph directory structures may suffer from the problem of having dangling pointers to non-existent files.
(C) Acyclic-graph directory structures may have the problem that a file’s reference count is not 0, but it cannot be accessed.
(D) Garbage collection is to recover unused disk space. It is necessary only when there are possible cycles in the directory structures.

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

這一題的完整詳解

核心觀念

這題的四個選項幾乎逐句對應 Silberschatz《Operating System Concepts》目錄結構一節的演進:

結構能否共用檔案/目錄新問題
樹狀(tree-structured)不能共用—
無環圖(acyclic-graph)可透過連結(link)共用刪除時可能留下懸空指標;用參照計數決定何時真正刪除
一般圖(general graph)允許形成環環會讓「參照計數不為 0、卻已無法存取」的節點出現 → 需要垃圾回收

選項分析

  • (A) 正確。 樹狀目錄的定義就是每個檔案/子目錄只有一個父目錄,不允許共用;一旦用連結讓同一檔案出現在兩個位置,結構就變成無環圖(或一般圖),不再是樹。
🔒

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

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

免費註冊

第 2 題

Assume there are four frames in the system. Given the memory reference pattern in terms of frame numbers, 50,40,80,20,50,10,80,4050, 40, 80, 20, 50, 10, 80, 40, which of the following statements are true?

(A) There are 5 page faults if LRU (least recently used) replacement algorithm is used.
(B) There are 5 page faults if optimal page-replacement algorithm is used.
(C) LRU can never exhibit Belady's anomaly.
(D) A process is thrashing if it spends more time in paging than execution. The effects of thrashing can be limited by using a global replacement algorithm.

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

這一題的完整詳解

核心觀念

本題考查頁面置換演算法的缺頁次數、Belady anomaly,以及 thrashing(顛簸)的成因與控制方式。

  • 缺頁(page fault):參照的頁面不在任何一個實體頁框中時,必須載入該頁面,記為一次缺頁。
  • LRU(least recently used):缺頁且頁框已滿時,置換「距離現在最久未被使用」的頁面。
  • 最佳置換(optimal page replacement):缺頁且頁框已滿時,置換「未來最晚才會再被使用」的頁面;若某頁之後不再使用,優先置換該頁。
  • Belady anomaly:增加頁框數後,缺頁次數反而增加的現象。LRU 是 stack algorithm,不會發生此現象。
  • Thrashing:程序花在處理缺頁與頁面調入、調出上的時間,超過實際執行時間。採用區域置換可減少程序互相搶奪頁框造成的影響。

解題方法

共有 44 個頁框,依序參照:

50, 40, 80, 20, 50, 10, 80, 4050,\ 40,\ 80,\ 20,\ 50,\ 10,\ 80,\ 40

下表每列列出參照後的頁框內容;「缺」表示該次參照造成缺頁。

參照頁面LRU 頁框內容LRU 缺頁?最佳置換頁框內容最佳置換缺頁?
5050缺50缺
4050, 40缺50, 40缺
8050, 40, 80缺50, 40, 80缺
2050, 40, 80, 20缺50, 40, 80, 20缺
5050, 40, 80, 20命中50, 40, 80, 20命中
1050, 10, 80, 20缺50, 40, 80, 10缺
8050, 10, 80, 20命中50, 40, 80, 10命中
4040, 10, 80, 20缺50, 40, 80, 10命中

LRU 的計算

🔒

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

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

免費註冊

第 3 題

Assume both the index block and data block use the same block size of 1 KB, and assume each entry of the index block consists of 4 bytes. Which of the following statements are true?

(A) The maximum file size that can be supported for single-level indexed allocation is 2182^{18} bytes.
(B) Two-level indexed allocation uses a first-level index block to point to a set of second-level index blocks. The maximum file size that can be supported by a two-level indexed allocation is 2262^{26} bytes.
(C) Both linked allocation and indexed allocation do not suffer from external fragmentation.
(D) For an application requiring direct access, it is better to use linked allocation than indexed allocation.

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

這一題的完整詳解

核心觀念

本題考檔案配置方式的可支援檔案大小、外部碎裂,以及直接存取能力。

索引配置(indexed allocation)把資料區塊位址存放在索引區塊中。索引區塊可容納的位址數為:

索引區塊大小每個索引項目大小\frac{\text{索引區塊大小}}{\text{每個索引項目大小}}

若每個索引區塊有 NN 個項目,單層索引最多可指向 NN 個資料區塊;兩層索引最多可指向 N2N^2 個資料區塊。檔案大小上限等於可指向的資料區塊數乘上資料區塊大小。

解題方法

區塊大小為 1 KB=2101\text{ KB}=2^{10} bytes,每個索引項目為 4=224=2^2 bytes,因此一個索引區塊可容納:

21022=28=256\frac{2^{10}}{2^2}=2^8=256

個區塊位址。

單層索引可指向 282^8 個資料區塊;兩層索引則由第一層指向 282^8 個第二層索引區塊,每個第二層索引區塊再指向 282^8 個資料區塊。

選項分析

🔒

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

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

免費註冊

第 4 題

Buddy system and Slab allocation are two techniques for allocating memory for kernel processes. Which of the following statements are true?

(A) With the buddy system, memory requests can be satisfied very quickly because objects are created in advance.
(B) In Slab allocation scheme, a slab may consist of both used and free objects.
(C) Using the buddy system, a request for 29 KB memory will be satisfied with a 36 KB segment of memory.
(D) Using the Slab allocation scheme, no memory is wasted due to fragmentation.

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

這一題的完整詳解

核心觀念

Buddy system 與 Slab allocation 都用於核心記憶體管理,但分配的對象不同:

  • Buddy system(夥伴系統):以 22 的冪次大小管理記憶體區塊。若請求大小不是 22 的冪次,會分配足以容納請求的最小區塊。
  • Slab allocation(Slab 配置):以 slab 作為容器,slab 內含多個同一類型或大小的物件。物件可以是已使用,也可以是空閒狀態。

解題方法

逐項對照敘述與兩種配置器的特性:Buddy system 的重點是區塊拆分與合併;Slab allocation 的重點是預先建立並重複使用核心物件。遇到 Buddy system 的容量題,則將請求大小向上取整至最小的 22 的冪次。

選項分析

(A) 錯誤。
Buddy system 能快速配置記憶體,主要是因為它將記憶體區塊按 22 的冪次管理,並透過拆分區塊滿足請求。題目所說「物件預先建立」是 Slab allocation 的特性,不是 Buddy system 的原因。

(B) 正確。
Slab 內含多個物件;配置器會追蹤物件的使用狀態。因此,一個 slab 可以同時包含已使用與空閒的物件,這類 slab 也稱為部分使用的 slab。

🔒

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

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

免費註冊

第 5 題

Consider a disk queue with requests for blocks on cylinders in the listed order: 120,25,5,11,80,185,90,85120, 25, 5, 11, 80, 185, 90, 85. If the disk head is initially at cylinder 88 and is moving upward to the next service cylinder 90, which of the following statements are true?

(A) If SSTF (Shortest seek-time first) is used, the requests will be serviced in the order of 90,85,80,120,185,25,11,590, 85, 80, 120, 185, 25, 11, 5.
(B) If C-SCAN (Circular SCN) is used, the requests will be serviced in the order of 90,120,185,85,80,25,11,590, 120, 185, 85, 80, 25, 11, 5.
(C) SSTF may suffer from the problem of starvation.
(D) C-SCAN is a variant of SCAN, designed to reduce the disk seek time needed by SCAN.

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

這一題的完整詳解

核心觀念

磁碟排程的目標是安排磁頭服務請求的順序。這題考查兩種排程方式:

  • SSTF(最短尋找時間優先):每次選擇距離目前磁頭位置最近的待處理請求。
  • C-SCAN(循環掃描):磁頭固定朝一個方向移動,沿途服務請求;到達磁碟末端後,回到另一端,再繼續朝原方向移動。這種方式讓不同位置的請求有較一致的等待時間。

題目中的磁頭初始位於第 8888 柱面,正向上移動,下一個服務柱面是第 9090 柱面。

解題方法

SSTF

每一步都以磁頭「目前所在柱面」為基準,計算它到所有未服務請求的距離:

尋道距離=∣請求柱面−目前柱面∣\text{尋道距離} = |\text{請求柱面} - \text{目前柱面}|

磁頭從 8888 前往最近的請求 9090。之後依序比較剩餘請求與目前位置的距離:

  • 位於 9090 時,最近的是 8585,距離 55。
  • 位於 8585 時,最近的是 8080,距離 55。
  • 位於 8080 時,最近的是 120120,距離 4040。
  • 位於 120120 時,最近的是 185185,距離 6565。
  • 位於 185185 後,剩下的請求由近至遠為 25、11、525、11、5。

因此 SSTF 的服務順序為:

🔒

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

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

免費註冊

第 6 題

System calls are the interface between application programs and kernel. What descriptions about system calls are correct?

(A) Just like hardware devices that generate interrupts, system calls also generate interrupts and jump to the kernel.
(B) Just like hardware devices, there are also vector entries for system calls and they point to interrupt service routines for both hardware and software interrupts.
(C) If there are many parameters to a system call, the user program can store all parameters in a table and pass the address of the table as a parameter to the system call.
(D) If memory copy between kernel and user program is heavy, it can be offloaded to DMA.

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

這一題的完整詳解

核心觀念

系統呼叫(system call)是應用程式向作業系統核心請求服務的介面。呼叫時,處理器會從使用者模式切換到核心模式,依照系統呼叫編號與參數進入核心中的處理程序。

常見實作會以陷阱(trap)或軟體中斷觸發這次轉換。硬體中斷通常由裝置非同步產生;系統呼叫則由正在執行的程式同步觸發。兩者的觸發來源不同,但都能透過向量表找到對應的核心處理常式。

解題方法

逐項檢查敘述是否符合系統呼叫的執行方式、向量表設計、參數傳遞機制,以及 DMA 的用途。判斷時要區分「硬體裝置產生的中斷」與「程式執行指令所觸發的陷阱」,也要分清 DMA 傳輸與一般記憶體複製。

選項分析

  • (A) 正確。 系統呼叫可透過陷阱或軟體中斷進入核心,造成控制流程轉入核心處理常式。它和硬體中斷一樣會引發核心端的處理流程,但觸發來源不同:硬體中斷來自裝置,系統呼叫則由程式執行特定指令同步觸發。
🔒

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

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

免費註冊

第 7 題

State of a process switches between ready, running, and waiting, when device interrupt, clock interrupt, or system call happens. Suppose now a process is in the running state.

(A) When a device interrupt happens, the process enters the waiting state first.
(B) When a clock interrupt happens, the process enters the ready state first.
(C) When an I/O system call is invoked, the process enters the waiting state first.
(D) When a non-I/O system call is invoked, the process enters the ready state first.

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

這一題的完整詳解

核心觀念

本題考三態行程模型中,行程狀態如何隨事件轉換:

  • 執行中(running)→ 就緒(ready):行程被中斷或排程器搶先,暫時讓出處理器。
  • 執行中(running)→ 等待(waiting):行程必須等待某項事件完成,例如等待 I/O 操作。
  • 等待(waiting)→ 就緒(ready):行程等待的事件完成,可以再次參與排程。

判斷時要看事件是否讓「目前執行中的行程」等待,或只是讓另一個等待中的行程恢復就緒。

解題方法

題目已指定某行程目前在執行中。逐項判斷事件是否會使它放棄處理器,或因等待 I/O 而阻塞:

  • 時鐘中斷通常觸發時間片檢查,使執行中的行程回到就緒狀態。
  • I/O 系統呼叫要求行程等待 I/O 完成,因此行程進入等待狀態。
  • 非 I/O 系統呼叫本身不代表行程必須等待,也不會必然使它回到就緒狀態。
🔒

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

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

免費註冊

第 8 題

In message passing for inter-process communication, with send()send() and receive()receive() being two system calls, if send()send() in sender is non-blocking but receive()receive() in receiver is blocking:

(A) If receive()receive() happens before send()send(), the receiver will not get the message.
(B) If receive()receive() happens after send()send(), the receiver will get the message.
(C) If now reversed, send()send() in sender is blocking and receive()receive() in receiver is non-blocking. If receive()receive() happens before send()send(), the receiver will get the message.
(D) Continued from (C), if receive()receive() happens after send()send(), the receiver will not get the message.

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

這一題的完整詳解

核心觀念

本題考「阻塞(blocking)」與「非阻塞(non-blocking)」訊息傳遞的差異:

  • 阻塞式 send():若接收端尚未接收訊息,傳送端會等待;接收端取走訊息後,send() 才能完成。
  • 非阻塞式 send():傳送端送出訊息後即可繼續執行,不必等待接收端取走。
  • 阻塞式 receive():若訊息尚未到達,接收端會等待;訊息到達後才完成接收。
  • 非阻塞式 receive():呼叫時若沒有可接收的訊息,便立即返回,不會等待稍後送達的訊息。

依標準訊息傳遞模型,已送出的訊息會保留,直到接收端取得。

解題方法

逐一判斷呼叫先後順序,再看阻塞的一方是否會等待另一個呼叫:

  1. 原始情況是非阻塞式傳送、阻塞式接收。接收先呼叫時,接收端等待;傳送稍後發生,訊息到達後接收端取得訊息。傳送先呼叫時,訊息先送出,稍後的接收仍可取得訊息。
  2. 反轉後是阻塞式傳送、非阻塞式接收。接收先呼叫時,因沒有訊息而立即返回;之後的傳送端會等待接收,無法讓已返回的接收呼叫再取得訊息。傳送先呼叫時,傳送端等待接收;
🔒

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

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

免費註冊

第 9 題

For a user thread there can be a corresponding kernel thread. Do they both maintain stack and PCB (process control block)? Separately or jointly? What possibilities below are valid?

(A) User thread has its stack and PCB, but the corresponding kernel thread does not have them.
(B) User thread and kernel thread share the same stack and PCB.
(C) User thread and kernel thread have their own stack separately but PCB jointly.
(D) User thread and kernel thread have their own stack and PCB separately.

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

這一題的完整詳解

核心觀念

題目考的是使用者層級執行緒(user thread)與核心層級執行緒(kernel thread)的對應關係,以及執行緒和行程控制資料的歸屬。

  • 堆疊(stack)屬於執行緒。使用者程式執行時使用使用者堆疊;進入核心執行時,對應的核心執行緒使用核心堆疊。兩者分開維護。
  • PCB(process control block,行程控制區塊)屬於行程,記錄行程層級的資訊。同一行程中的執行緒共用該行程的 PCB。
  • 每個執行緒有自己的執行緒控制資料,通常稱為 TCB(thread control block,執行緒控制區塊)。TCB 不等於 PCB。

解題方法

🔒

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

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

免費註冊

第 10 題

Modern operating systems adjust priority in scheduling processes. What strategies are commonly used?

(A) Increase priority when a process uses up its quantum.
(B) Increase priority when a process has frequent I/O.
(C) Increase priority when a process wakes up from a long sleep.
(D) Increase priority for a foreground process.

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

這一題的完整詳解

核心觀念

本題考動態優先權排程:作業系統會依行程的 CPU 使用情形、等待行為與互動需求調整優先權,讓 CPU 密集型行程不會長期壟斷處理器,也讓需要快速回應的行程能及時執行。

常見判斷原則是:剛用完一整個時間片的行程,通常降低優先權;常等待 I/O 或屬於前景互動工作的行程,通常提高優先權。 有些排程器也會讓長時間休眠的行程在喚醒後得到優先權提升,改善互動回應。

解題方法

逐項判斷各行為代表的排程需求:

  • 行程用完完整時間片,表示它持續占用 CPU,通常應降低優先權。
  • 行程頻繁等待 I/O,表示它多半不是長時間占用 CPU 的工作,提升優先權可縮短 I/O 完成後的等待。
  • 行程長時間休眠後喚醒,動態優先權排程常會讓其近期 CPU 使用量影響逐漸衰減,或在喚醒時給予優先權提升,以改善回應。
  • 前景行程直接服務使用者操作,通常需要較快得到 CPU。

選項分析

🔒

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

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

免費註冊

第 11 題

Consider the CPU performance. Which of the following statements are correct?

(A) If you want to decrease the response time of a task, you can promote your PC by replacing the old single-core CPU with a new multi-core CPU and using a new operating system that can partition a task into several load-balanced sub-tasks and execute all sub-tasks on all cores concurrently. Assume the performance of the single-core CPU is the same as that of each core of the new multi-core CPU.
(B) If we run two programs on two CPUs of different ISAs to perform the same task, the CPU with smaller CPI must have less CPU time than the other CPU since smaller CPI also implies that the required number of cycles to complete a task is also less than that of the other CPU.
(C) The CPU time of performing a program on a CPU is determined by the instruction count, the CPI, and the clock rate of the CPU.
(D) Consider using the metric of Millions of Instructions per Second (MIPS) to measure CPU performance. Two programs are run on single-core CPUs CAC_A and CBC_B of different ISAs to solve the same task. CAC_A requires less time than CBC_B to complete the task while CAC_A has less MIPS than CBC_B. The aforementioned facts imply that CAC_A is likely a CISC-based CPU and CBC_B is a RISC-based CPU.

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

這一題的完整詳解

核心觀念

CPU 執行時間由指令數、平均每指令週期數與時脈頻率共同決定:

CPU time=Instruction Count×CPIClock Rate\text{CPU time} = \frac{\text{Instruction Count}\times\text{CPI}}{\text{Clock Rate}}

其中,Instruction Count 是完成工作所需的指令數,CPI 是平均每條指令所需的時脈週期數,Clock Rate 是每秒的時脈週期數。比較不同 ISA 的 CPU 時,指令數與 CPI 都可能不同,不能只看其中一項判斷執行時間。

MIPS 的定義為:

MIPS=Instruction CountCPU time×106\text{MIPS} = \frac{\text{Instruction Count}}{\text{CPU time}\times 10^6}

因此,MIPS 同時受指令數與 CPU time 影響;不同 ISA 的指令數差異很大,MIPS 不適合單獨作為跨 ISA 的效能比較指標。

解題方法

逐項檢查敘述是否符合 CPU time 公式與平行處理原理。對 D,將 MIPS 定義與執行時間的關係合併,判斷兩個 CPU 完成相同工作時,指令數的相對大小,再評估這種結果是否符合 CISC 與 RISC 的常見特性。

選項分析

(A) 正確。 題目已假設作業系統能將工作切成負載平衡的子工作,並讓多核心同時執行。若各子工作可平行處理,原本由單核心依序完成的工作便能分散到多個核心,縮短回應時間。新 CPU 的每核心效能與舊單核心相同,不妨礙多核心透過平行執行提升整體效能。

(B) 錯誤。 CPI 較小不代表完成工作的總週期數較少,因為總週期數還取決於指令數:

🔒

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

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

免費註冊

第 12 題

Consider the instruction set of a 32-bit MIPS CPU. Which of the following statements are correct?

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

(A) One of the reasons why there are only 32 registers in the CPU is that the use of more registers will decrease the number of instructions that can be encoded in an instruction.
(B) As generating a MIPS instruction, a compiler generally assigns a register to the most frequently used variable to diminish memory access time.
(C) The reason why MIPS does not support the instructions of bltblt (branch less than) and bgtbgt (branch greater than) is that the hardware design of “greater than” or “less than” is more complex than “equal” and “not equal”, which may make the design of supporting bltblt and bgtbgt have less clock rate.
(D) The above figure shows a MIPS assembly program. In the procedure prologue, three registers were saved: rara, s1s1, and a0a0. In fact, only rara and s1s1 need to be stored and a0a0 does not.

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

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

這一題的完整詳解

核心觀念

本題考查 MIPS 的指令編碼、暫存器配置、分支電路設計,以及遞迴呼叫時的暫存器保存。

  • 指令編碼:32 位元 MIPS 採固定長度指令。指定 RR 個暫存器,需要 ⌈log⁡2R⌉\lceil\log_2 R\rceil 個位元;32 個暫存器需 5 位元。
  • 暫存器配置:暫存器存取比主記憶體快,編譯器會優先讓經常使用的變數留在暫存器。
  • 分支判斷:比較電路的延遲會影響處理器的關鍵路徑,進而限制時脈頻率。
  • 遞迴呼叫:除了返回位址,也須保存呼叫後仍要使用、且會遭修改的資料。

解題方法

圖中的 fib 先配置 12 位元組堆疊空間,保存 $ra、$s1 與 $a0;L1 是標籤,其中兩次 jal fib 都是遞迴呼叫,且每次呼叫前均將 $a0 減 1。共同的 EXIT 則還原這三個暫存器,再返回呼叫端。

前三個選項依指令格式與硬體設計判斷;選項 (D) 則追蹤 $a0 在兩次遞迴呼叫前後的值。關鍵程式如下:

L1:
    addi $a0, $a0, -1
    jal  fib
    addi $s1, $v0, 0
    addi $a0, $a0, -1
    jal  fib
    add  $v0, $v0, $s1

EXIT:
    lw   $ra, 0($sp)
    lw   $a0, 8($sp)
    lw   $s1, 4($sp)
    addi $sp, $sp, 12
    jr
🔒

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

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

免費註冊

第 13 題

Consider the 32-bit MIPS CPU. Which of the following statements are correct?

(A) Floating-point instructions have different register set from integer instructions.
(B) The code sequence (lui (lui\ t1,288;\ ori\ t1,t1,t1,26)performstheoperationofloadingaconstantperforms the operation of loading a constant0x0120001Aintoregisterinto registert1.(C)Considertheadditionofthreefloating−pointnumbers. (C) Consider the addition of three floating-point numbers (a+b+c)onaparallelprogram.Theadditionresultsofon a parallel program. The addition results of(a+b)+candanda+(b+c)arealwaysthesame,i.e.,floating−pointnumberadditionholdstheassociativity.(D)Assumethevalueofregisterare always the same, i.e., floating-point number addition holds the associativity. (D) Assume the value of registerPCisis0xAB05FF84.Thehighestaddressthatinstruction. The highest address that instruction jcangotoiscan go to is0xAFFFFFFC$.

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

這一題的完整詳解

核心觀念

本題考查三個 MIPS 概念:浮點數與整數使用的暫存器、lui/ori 組合常數,以及跳躍指令 j 的目標位址組成;另考查浮點數加法在有限精度下是否具有結合律。

解題方法

逐項依指令定義判斷:

  • lui 將 16 位元立即值放入暫存器高 16 位,低 16 位補零;ori 再將立即值與暫存器內容做位元 OR。
  • MIPS 的 j 指令目標位址由 PC+4 的最高 4 位元、指令中的 26 位元目標欄位,以及末尾兩個零位元組成。
  • 浮點數運算須考慮有限精度捨入,不能直接假定符合實數的代數性質。

選項分析

(A) 正確。 MIPS 浮點運算使用浮點暫存器組,例如 $f0 至 $f31;整數運算使用一般暫存器組,例如 $0 至 $31。兩者是不同的暫存器組。部分指令可在兩組暫存器間搬移資料,但不會改變浮點與整數運算使用不同暫存器組的事實。

(B) 正確。 指令中的立即值以十進位表示,因此 288=0x0120288=0x0120、26=0x001A26=0x001A。

lui $t1,288⟹$t1=0x0120 0000\texttt{lui \$t1,288} \quad\Longrightarrow\quad \$t1=0x0120\,0000

接著執行 ori:

0x0120 0000 OR 0x0000 001A=0x0120 001A0x0120\,0000\ \mathbin{\mathrm{OR}}\ 0x0000\,001A =0x0120\,001A
🔒

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

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

免費註冊

第 14 題

Consider the 32-bit MIPS CPU. Which of the following statements are correct?

(A) The reason why sometimes the assembler replaces the following instructions, beq $s2,$s3,L1; add $t0,$s1,$s2, with the following code sequence, bne $s2,$s3,L2; j L1; L2: add $t0,$s1,$s2, is that the hardware to realize beq is slower than that to realize bne and j is also a faster instruction than beq due to no need to access registers.
(B) Consider the 32-bit floating-point numbers using IEEE Std. 754. The smallest positive single-precision denormalized number is 1.0×2−1491.0\times2^{-149}.
(C) The concept of sticky bit is to use two bits to record the number of 1s in the already rounded bits.
(D) Consider the following code sequence running on one core of a multi-core CPU:

try: add  $t0, $zero, $s0
     ll   $t1, 0($s2)
     sc   $t0, 0($s2)
     beq  $t0, $zero, try
     add  $s0, $zero, $t1

The atomic pair of instructions (ll, sc) in the code sequence protects the data at memory 0(0(s2) from write of another core during the data swap of register s0s0 and memory 0(0(s2).

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

這一題的完整詳解

核心觀念

本題考查四個觀念:MIPS 條件分支與跳躍指令、IEEE 754 單精度次正規數、浮點捨入的黏著位元,以及 MIPS 的 ll/sc 原子更新機制。

解題方法

逐項檢查指令的硬體用途與資料表示定義:

  • beq、bne 都是比較暫存器後決定是否分支的條件分支指令。
  • IEEE 754 單精度次正規數的指數欄為全零,且沒有隱含的前導 11。
  • 黏著位元記錄被捨棄的低位中是否曾出現 11。
  • ll/sc 以連結載入建立保留狀態;若期間發生衝突寫入,條件儲存就會失敗,程式可重試。

選項分析

(A) 錯誤。 beq 與 bne 都需要比較暫存器,硬體速度沒有題述的差異;j 不讀取暫存器,也不能據此斷定它比 beq 快。條件分支改寫成反向分支加跳躍,常見原因是分支目標超出 beq 的位移範圍:MIPS 條件分支使用 16 位元帶符號位移,而跳躍指令可使用較大的目標欄位。

此外,傳統 MIPS 有分支延遲槽,改寫時必須一併處理延遲槽中的指令;題目列出的序列不能在所有情況下直接視為等價改寫。

🔒

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

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

免費註冊

第 15 題

Consider the arithmetic operation unit in the following figure for 32-bit MIPS CPU. Which of the following statements are correct?

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

(A) As the operation unit performs a multiplication, the Divisor register acts as a multiplicand register and the Remainder register acts as a Product register. The lower word of Remainder register accommodates the dividend and the higher word of Product register accommodates the multiplier.
(B) The performance gain of Booth’s algorithm comes from consecutive 0s or 1s in the multiplier.
(C) Using the non-restoring division algorithm (NRDA) and restoring division algorithm (RDA) to perform a division of 7 divided by 2 that is represented by a signed 4-bit binary number, NRDA requires 5 subtractions and 3 additions while RDA requires 2 subtractions and 3 additions.
(D) If we want to improve the performance of 32-bit ALU, we can use carry look-ahead adder to avoid waiting for carry propagation. To exploit the hierarchical design concept, we also can apply group propagate and group generate to design a multi-level carry look-ahead adder. The multi-level design owns the benefit of using systematic way to deal with the adder of large bit number in a simple way without the other benefit such as delay.

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

這一題的完整詳解

核心觀念

本題考查四個觀念:乘除法硬體的暫存器共用、Booth 乘法編碼、恢復式與非恢復式除法,以及階層式超前進位加法器。

判斷重點是:乘數放在哪一半暫存器、Booth 在哪些位元組合下執行加減、除法是否立即恢復負餘數,以及階層式進位是否具有延遲上的優點。

解題方法

原頁明確寫出:運算單元用於 32 位元 MIPS CPU;(C)宣稱 NRDA 為「5 次減法、3 次加法」,RDA 為「2 次減法、3 次加法」。所附頁面未顯示題幹所稱的運算單元圖;(A)以下依標準 MIPS 乘除法共用暫存器架構判斷,其餘選項可直接由演算法與進位公式分析。

選項分析

(A)錯誤:乘數應放在 Product 暫存器的低位半部。

標準的共用硬體可將:

  • Divisor 暫存器用作被乘數(Multiplicand)暫存器。
  • Remainder 暫存器用作乘積(Product)暫存器。

但進行乘法時,64 位元 Product 暫存器的初始配置為:

0⏟高 32 位元  ∣  乘數⏟低 32 位元\underbrace{0}_{\text{高 32 位元}} \;\big|\; \underbrace{\text{乘數}}_{\text{低 32 位元}}

高位半部用來累積部分乘積,低位半部初始放置乘數。選項卻說高位半部放乘數,並在乘法情境中把低位半部稱為放置「被除數」,因此整個敘述錯誤。

(B)正確:連續相同位元不需要執行加減。

Booth 演算法檢查乘數目前位元 qiq_i 與前一位元 qi−1q_{i-1},最低位之外補 q−1=0q_{-1}=0。令被乘數為 MM,規則如下:

位元組合 (qi,qi−1)(q_i,q_{i-1})對部分乘積的運算
0000不加不減
0101加上 MM
1010減去 MM
1111不加不減

每輪仍執行算術右移。連續的 00 或 11 形成 0000、1111,因此只在位元轉換處執行加減,符合選項敘述。Booth 演算法講義

例如,一串連續的 11 可寫成:

001111002=26−2200111100_2=2^6-2^2

乘上 MM 時,可用兩個位移後的項相減取代四個部分乘積相加。這項優點主要是減少加減次數,並不表示所有乘數都能縮短固定迭代硬體的週期數。

(C)錯誤:兩種演算法的運算次數被對調。

被除數與除數分別為:

7=01112,2=001027=0111_2,\qquad 2=0010_2

採用除數先左移 4 位、再逐步右移的流程,對齊後的除數依序為:

32, 16, 8, 4, 232,\ 16,\ 8,\ 4,\ 2

此處使用足夠寬的內部暫存器保存對齊除數及帶符號的部分餘數。

🔒

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

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

免費註冊

第 16 題

Using MIPS processor design and implementation for example, which of the following statements are correct?

(A) A control signal generally called a “clock” is used widely to control what most combinational components (such as ALU, multiplexer, etc.) should do.
(B) If every instruction must be executed in one clock cycle, the implementation must include at least two independently operable memory units.
(C) If every instruction can be executed using multiple clock cycles and the execution is not pipelined, this can result in the cheapest-possible hardware design (even considering the may-be-required stage latches).
(D) For pipelined processor design, at least two independently operable memory units are a must.

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

這一題的完整詳解

核心觀念

處理器由組合邏輯元件與狀態元件組成。組合邏輯元件(如 ALU、多工器)依當下輸入產生輸出;狀態元件(如暫存器、記憶體)則在時脈邊緣更新或存取資料。時脈用來同步狀態更新,通常不是直接決定組合邏輯要執行哪種運算的控制訊號。

判斷記憶體需求時,關鍵是看處理器在同一個時脈週期內是否必須同時取指令、存取資料。若兩項操作必須並行,硬體就要能同時提供這兩種存取能力。

解題方法

逐一檢查各敘述的時序與硬體需求:

  • 單週期處理器要求每條指令在一個週期內完成。lw、sw 等指令在同一週期中既要讀取指令,也要存取資料記憶體,因此需要可獨立並行操作的指令與資料記憶體。
  • 多週期、非管線處理器可把一條指令拆成多個週期,並在不同週期重複使用同一硬體元件,減少硬體數量。
  • 管線處理器同時處理多條指令的不同階段;取指令與資料存取可能在同一週期發生,因此必須具備兩種可並行的記憶體存取能力。

選項分析

(A) 錯誤。
時脈主要用來同步狀態元件的更新時機,例如在時脈邊緣寫入暫存器。ALU 要執行加法或邏輯運算,通常由控制訊號(例如 ALU 控制碼)決定;多工器選擇哪個輸入,也由選擇訊號決定。

🔒

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

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

免費註冊

第 17 題

Given the following figures and tables for a few MIPS sample instructions, which of the following statements are correct?

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

(A) The binary machine instruction encoding for “and r4,r4, r6, r8”(r8” (r4=r6&r8)isr6\mathbin{\&}r8) is 0000\ 0000\ 1100\ 1000\ 0010\ 0000\ 0010\ 0100.(B)Thebinarymachineinstructionencodingfor“sw. (B) The binary machine instruction encoding for “sw r5, -7(r9)”isr9)” is 1010\ 1101\ 0010\ 0101\ 1111\ 1111\ 1111\ 1001.(C)Theinstruction“beq...”canresultinanext. (C) The instruction “beq ...” can result in a next PCvalueof[(theaddressof“beq...”)+(theaddressfieldin2’scomplementform)].(D)TheinstructionR−type“sub...”hasavalue of [(the address of “beq ...”) + (the address field in 2’s complement form)]. (D) The instruction R-type “sub ...” has aBranch=0,, RegDst=1,, ALUSrc=0,“ALUcontrol”output, “ALU control” output =0110,and, and MemtoReg=0$.

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

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

這一題的完整詳解

核心觀念

本題考查 MIPS 指令編碼、分支位址計算,以及單周期資料路徑的控制訊號。

  • R 型指令:欄位依序為 opcode、rs、rt、rd、shamt、funct,位元數為 6、5、5、5、5、66、5、5、5、5、6。
  • I 型指令:欄位依序為 opcode、rs、rt、immediate,位元數為 6、5、5、166、5、5、16;負立即值以 16 位元二補數表示。
  • beq 分支目標:以目前指令位址加 44 為基準,再加上符號延伸後、左移兩位的立即值。

解題方法

原卷圖中,R 型指令的 opcode 為 00,sw 的 opcode 為 4343;表格列出 and 的 funct 為 100100,sub 的 ALU 控制碼為 0110。資料路徑也顯示:分支立即值先經符號延伸與左移兩位,再與 PC+4PC+4 相加。

因此,編碼選項逐欄核對;分支選項依圖中的加法器連線判斷;控制訊號則依各多工器應選取的資料來源判斷。

選項分析

(A) 正確

指令 and $r4, $r6, $r8 的運算為:

R[4]←R[6]&R[8]R[4]\leftarrow R[6]\mathbin{\&}R[8]

第一個暫存器是目的暫存器,因此各欄位為:

欄位意義二進位
opcodeR 型指令000000
rs來源暫存器 r6r600110
rt來源暫存器 r8r801000
rd目的暫存器 r4r400100
shamt非移位指令,設為 0000000
functand100100

串接後為:

000000 00110 01000 00100 00000 100100

每四位重新分組:

0000 0000 1100 1000 0010 0000 0010 0100

與原卷 (A) 一致。

(B) 錯誤

原卷 (B) 印出的機器碼是:

1010 1101 0010 0101 1000 0000 0000 0111

sw $r5, -7($r9) 表示將 r5r5 的資料存入位址 $R[9]-7

🔒

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

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

免費註冊

第 18 題

We study the MIPS processor hazards using pipelined designs for a few typical instructions. Which of the following statements are correct?

(A) If there are structural hazards, any contented hardware must be duplicated many copies to satisfy any possible needs, or else the pipelined processor cannot work properly.
(B) For sequentially fetched instructions, with a single pipeline, in-order issue and in-order completion of instructions are both guaranteed.
(C) For true-data dependence (read-after-write), data dependence detection and forwarding can effectively alleviate the hazards, while stalls are many times still required.
(D) For sequentially fetched instructions with a single pipeline, in-order issue can be designed to never cause anti-dependencies (write-after-read), while in doing loop unrolling, one must rename registers to remove other name-dependencies.

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

這一題的完整詳解

核心觀念

本題考查管線中的三類相依與指令順序:

  • 結構性危障(structural hazard):多個指令在同一時刻需要同一硬體資源,但資源不足。
  • 真實資料相依(RAW,read-after-write):後續指令要讀取前面指令尚未寫回的結果。
  • 名稱相依:反相依(WAR,write-after-read)與輸出相依(WAW,write-after-write)。它們來自重複使用同一暫存器名稱,未必代表真正的資料傳遞。
  • 循序單管線通常依程式順序發射並完成指令;資料前推(forwarding)能縮短 RAW 危障造成的等待,但不一定能完全消除停滯。

解題方法

逐項檢查敘述是否把一種常見處理方式誤說成唯一方式,並區分「真實資料相依」與「暫存器名稱造成的相依」。結構性危障可以透過停滯化解;RAW 可用資料前推減少等待,但某些情況仍需停滯。循序單管線則維持指令順序,且較年輕指令不會在較早指令讀取來源值之前先寫入該暫存器。

選項分析

🔒

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

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

免費註冊

第 19 題

Memory design is typically hierarchical. Which of the following statements are correct?

(A) The purpose of such design is to make memory look both large and fast. Any application running with a hierarchical memory system will have faster average memory accesses compared with a flat, non-hierarchical memory system.
(B) Let the L1 cache be the closest-to-processor hierarchy of the memory system. In considering its role and performance, the hit time is a more important factor than the hit rate.
(C) A processor-issued memory address will be partitioned by the L1 cache into three fields: tag, index, and byte offset. Only one of these fields, the tag, needs to be stored in a proper cache line (or block) together with a valid bit, and other helpful information such as a dirty bit.
(D) Since processor accesses to L1 cache will miss, the average memory access time of a program is expressed as [(L1 cache hit time)+(next lower hierarchy hit time)×(L1 cache miss rate)][(\text{L1 cache hit time})+(\text{next lower hierarchy hit time})\times(\text{L1 cache miss rate})].

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

這一題的完整詳解

核心觀念

快取記憶體利用時間區域性與空間區域性,讓常用資料較可能留在較快的高階記憶體中。分析效能時,常用平均記憶體存取時間(AMAT):

AMAT=命中時間+未命中率×未命中代價\text{AMAT} = \text{命中時間} + \text{未命中率}\times\text{未命中代價}

多層快取中,較低層快取若也可能未命中,未命中代價就必須把後續存取成本納入。

解題方法

逐項檢查敘述是否符合快取的位址欄位、效能定義與 AMAT 公式。尤其要分清楚「較低層快取的命中時間」和「L1 未命中代價」:兩者只有在較低層必定命中時才相同。

選項分析

  • (A) 錯誤。 階層式記憶體的目標是讓記憶體看起來兼具大容量與高速度。但「任何應用程式的平均存取都會更快」並不成立。若程式缺乏區域性,快取未命中率可能很高,階層式存取也不保證快於平坦式記憶體。

  • (B) 正確。 L1 命中時間會影響每次 L1 存取的延遲,也可能限制處理器時脈;L1 命中率則主要影響未命中的頻率。因此在考量最靠近處理器的 L1 快取時,命中時間通常特別重要。

🔒

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

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

免費註冊

第 20 題

In a computer system, cache memory and main memory are two intermediate memory hierarchies. Which of the following statements are not correct?

(A) Both hierarchies are designed based on the same principle of typical applications: the Principle of Locality.
(B) The locality in a cache design is based on spatial locality and temporal locality; while the locality in the main memory design is based on only spatial locality, excluding temporal locality.
(C) For typical computer systems, the cache controller and virtual memory manager are both software to better lower their miss rates.
(D) Upon cache misses, to better utilize available hardware resources, CPU usually switches to execute other ready and waiting jobs.

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

這一題的完整詳解

核心觀念

本題考查記憶體階層如何利用局部性原理,以及快取與虛擬記憶體的管理方式。

局部性原理分為兩種:

  • 時間局部性:近期存取過的資料,短時間內再次被存取的機率較高。
  • 空間局部性:近期存取位置附近的資料,接著被存取的機率較高。

快取用較小、較快的記憶體保存近期常用資料;虛擬記憶體則以主記憶體搭配儲存裝置,讓程式能使用較大的位址空間。兩者都利用程式存取具有局部性的特徵,但管理者與未命中時的處理方式不同。

解題方法

逐項檢查三件事:兩種記憶體階層是否都利用局部性、快取與虛擬記憶體由硬體或軟體管理,以及快取未命中時處理器是否通常切換工作。題目問「哪些敘述不正確」,因此找出錯誤敘述即可。

選項分析

(A) 正確。
快取與主記憶體階層都利用程式的局部性特徵。快取依時間與空間局部性保存近期或鄰近資料;虛擬記憶體也利用程式在一段時間內集中存取部分位址的特性,將所需頁面留在主記憶體中。

🔒

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

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

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

Consider a system with a 32-bit logical address space, a page size of 4K bytes, and physical memory of size 256M bytes. For all the questions below, assume each entry in the page table consists of 4 bytes.

第 21 題

Assuming that the single-level page-table scheme is used, for a logical address 0xabcdef120xabcdef12, the value used to index the page table is ____.

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

這一題的完整詳解

核心觀念

單層頁表以邏輯位址中的頁號作為頁表索引。頁面大小為 4 KB=2124\text{ KB}=2^{12} bytes,因此邏輯位址最低 12 位是頁內位移,其餘位元是頁號。

解題方法

32 位元邏輯位址可分成:

頁號⏟32−12=20 位元 頁內位移⏟12 位元\underbrace{\text{頁號}}_{32-12=20\text{ 位元}} \ \underbrace{\text{頁內位移}}_{12\text{ 位元}}

將位址 0xabcdef120xabcdef12 的最低 12 位分離:

  • 頁內位移:0xf120xf12
  • 頁號:0xabcde0xabcde
🔒

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

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

免費註冊

第 22 題

Assuming that the two-level page-table scheme is used and the outer page table has 256 entries, for a logical address 0xabcdef120xabcdef12, the values used to index the outer and inner page tables are ____ and ____, respectively.

(A) A=0xabA=0xab, B=0xcdef12B=0xcdef12
(B) A=0xabA=0xab, B=0xcdeB=0xcde
(C) A=0xabcdA=0xabcd, B=0xef12B=0xef12
(D) A=0xabA=0xab, B=0xcdB=0xcd

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

這一題的完整詳解

核心觀念

分頁系統會把邏輯位址拆成兩部分:頁號與頁內位移。在兩層頁表中,頁號再拆成外層頁表索引與內層頁表索引。

頁面大小為 4K=2124\text{K}=2^{12} bytes,因此頁內位移占 1212 位元。邏輯位址共 3232 位元,頁號占:

32−12=20 位元32-12=20\text{ 位元}

外層頁表有 256=28256=2^8 個項目,因此外層索引占 88 位元;內層索引占剩餘的 20−8=1220-8=12 位元。

解題方法

將邏輯位址 0xabcdef120xabcdef12 依位元欄位切分:

  • 最低 1212 位元是頁內位移,即最後 33 個十六進位數字:0xF120xF12。
  • 剩下的 2020 位元是頁號:0xABCDE0xABCDE。
  • 頁號高 88 位元作為外層索引:0xAB0xAB。
  • 頁號低 1212 位元作為內層索引:0xCDE0xCDE。

因此:

A=0xAB,B=0xCDEA=0xAB,\qquad B=0xCDE

每個頁表項目為 44 bytes、實體記憶體大小為 256M256\text{M} bytes,均不影響本題的索引切分。

選項分析

🔒

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

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

免費註冊

第 23 題

Assuming that the two-level page-table scheme is used and the outer page table has 256 entries, each process may need up to ____ bytes of memory space for the page table.

(A) 210+2222^{10}+2^{22}
(B) 28+2122^8+2^{12}
(C) 210+2142^{10}+2^{14}
(D) 213+2252^{13}+2^{25}

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

這一題的完整詳解

核心觀念

頁表記錄虛擬頁面到實體頁框的對應。頁表每個項目占 44 bytes,因此頁表所需空間取決於頁表項目數量。

虛擬位址可分為「虛擬頁碼」與「頁內位移」;兩層頁表再將虛擬頁碼切分為外層索引與內層索引。

解題方法

頁面大小為 4K=2124\text{K}=2^{12} bytes,因此頁內位移占 1212 bits。3232-bit 虛擬位址剩下的位元數是虛擬頁碼:

32−12=20 bits32-12=20\text{ bits}

外層頁表有 256=28256=2^8 個項目,外層索引占 88 bits。內層索引占用其餘虛擬頁碼位元:

20−8=12 bits20-8=12\text{ bits}

因此,每張內層頁表最多有 2122^{12} 個項目。每項占 4=224=2^2 bytes,單張內層頁表大小為:

212×22=214 bytes2^{12}\times 2^2=2^{14}\text{ bytes}

外層頁表大小為:

28×22=210 bytes2^8\times 2^2=2^{10}\text{ bytes}

每個行程最多需要一張外層頁表,以及 282^8 張內層頁表。因此最大頁表空間為:

210+28×2142^{10}+2^8\times 2^{14}
🔒

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

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

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

Consider the following monitor solution to the 5 dining philosophers problem, where there are 5 chopsticks between 5 philosophers who sit at a round table. A philosopher needs to get both chopsticks on the right and left sides to eat. Suppose the index ii is incremented counterclockwise. Each philosopher ii invokes the operations pickup()pickup() and putdown()putdown() in the following sequence:

DiningPhilosophers.pickup(i);\text{DiningPhilosophers.pickup}(i);
EAT\text{EAT}
DiningPhilosophers.putdown(i);\text{DiningPhilosophers.putdown}(i);

The monitor is defined as follows:

monitor DiningPhilosophers{enum {THINKING; HUNGRY; EATING} state[5];condition self[5];void pickup(int i) {state[i]=HUNGRY;test(i);if (state[i]≠HUNGRY) self[i].wait();}void putdown(int i) {state[i]=THINKING;test((i+4) mod 5);test((i+1) mod 5);}void test(int i) {if ((state[(i+4) mod 5]≠EATING) &&(state[i]=HUNGRY) &&(state[(i+1) mod 5]≠EATING)) {state[i]=EATING;self[i].signal();}}initialization_code(){for (int i=0; i<5; i++)state[i]=THINKING;}}\begin{aligned} &\text{monitor DiningPhilosophers} \\ &\{\\ &\quad \text{enum }\{ \text{THINKING};\ \text{HUNGRY};\ \text{EATING} \}\ \text{state}[5];\\ &\quad \text{condition self}[5];\\ &\quad \text{void pickup(int }i\text{) }\{\\ &\qquad \text{state}[i]=\text{HUNGRY};\\ &\qquad \text{test}(i);\\ &\qquad \text{if (state}[i]\ne\text{HUNGRY) self}[i].\text{wait}();\\ &\quad \}\\ &\quad \text{void putdown(int }i\text{) }\{\\ &\qquad \text{state}[i]=\text{THINKING};\\ &\qquad \text{test}((i+4)\bmod 5);\\ &\qquad \text{test}((i+1)\bmod 5);\\ &\quad \}\\ &\quad \text{void test(int }i\text{) }\{\\ &\qquad \text{if }((\text{state}[(i+4)\bmod 5]\ne\text{EATING})\ \&\&\\ &\qquad\qquad (\text{state}[i]=\text{HUNGRY})\ \&\&\\ &\qquad\qquad (\text{state}[(i+1)\bmod 5]\ne\text{EATING}))\ \{\\ &\qquad\quad \text{state}[i]=\text{EATING};\\ &\qquad\quad \text{self}[i].\text{signal}();\\ &\qquad \}\\ &\quad \}\\ &\quad \text{initialization\_code}() \{\\ &\qquad \text{for (int }i=0;\ i<5;\ i++)\\ &\qquad\quad \text{state}[i]=\text{THINKING};\\ &\quad \}\\ &\} \end{aligned}

第 24 題

One statement in the above program is wrong. Name which statement.

(A) state[i]=HUNGRY\text{state}[i]=\text{HUNGRY}
(B) if (state[i]≠HUNGRY) self[i].wait()\text{if (state}[i]\ne\text{HUNGRY) self}[i].\text{wait}()
(C) state[i]=EATING\text{state}[i]=\text{EATING}
(D) self[i].signal()\text{self}[i].\text{signal}()

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

這一題的完整詳解

核心觀念

這題考的是監視器(monitor)中的條件變數,以及用哲學家狀態避免相鄰哲學家同時拿取同一根筷子。

哲學家 ii 只有在左右兩位哲學家都沒有進入 EATING 狀態時,才可進入 EATING。因此,test(i) 成功時會先將 state[i] 設為 EATING,再發出訊號;若條件不成立,哲學家仍維持 HUNGRY,並應等待條件變數。

解題方法

檢查 pickup(i) 呼叫 test(i) 後的兩種狀態:

  • 若左右鄰居都沒有在吃,test(i) 將 state[i] 設為 EATING。
  • 若至少一位鄰居正在吃,test(i) 不改變狀態,state[i] 仍是 HUNGRY。

因此,等待條件應判斷哲學家**尚未進入 EATING**時才等待,也就是:

if (state[i]≠EATING) self[i].wait()\text{if }(\text{state}[i]\ne\text{EATING})\ \text{self}[i].\text{wait}()

題目中的條件卻在 state[i] 不等於 HUNGRY 時等待,判斷方向錯誤。當哲學家仍是 HUNGRY、尚未取得兩根筷子時,程式反而不會等待,可能直接進入 EAT。

🔒

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

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

免費註冊

第 25 題

What is the purpose of the function test(i)\text{test}(i)?

(A) Check whether both right and left chopsticks are available.
(B) Check whether both neighbors are not EATING, and if both are not, eat.
(C) Check whether both right neighbors are HUNGRY, and if both are not, eat.
(D) Check whether either right neighbor or left neighbor is HUNGRY, and if yes, wake it up to eat.

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

這一題的完整詳解

核心觀念

這題考監視器中的狀態判斷,以及哲學家用餐問題的安全條件。test(i) 檢查哲學家 ii 是否符合開始用餐的條件:左右兩位鄰居都沒有在用餐,而且哲學家 ii 自己正處於飢餓狀態。

在程式中,哲學家 ii 的左右鄰居索引分別是 (i+4) mod 5(i+4)\bmod 5 與 (i+1) mod 5(i+1)\bmod 5。若條件成立,函式便把 state[i] 設為 EATING,並對 self[i] 發出訊號。

解題方法

直接逐項讀取 test(i) 的條件:

  • state[(i+4) mod 5] != EATING:左鄰居沒有在用餐。
  • state[i] = HUNGRY:哲學家 ii 正在等待用餐。
  • state[(i+1) mod 5] != EATING:右鄰居沒有在用餐。
🔒

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

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

免費註冊

第 26 題

What is the purpose of the function test((i+4) mod 5)\text{test}((i+4)\bmod 5)?

(A) Check whether my left neighbor is HUNGRY and its both neighbors are not EATING, and if both are not EATING, wake it up to eat.
(B) Check whether my right neighbor is HUNGRY and its both neighbors are not EATING, and if both are not EATING, wake it up to eat.
(C) Check whether my left neighbor is HUNGRY and its both neighbors are not HUNGRY, and if both are not HUNGRY, wake it up to eat.
(D) Check whether my right neighbor is HUNGRY and its both neighbors are not HUNGRY, and if both are not HUNGRY, wake it up to eat.

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

這一題的完整詳解

核心觀念

此題考的是監視器中的哲學家就餐問題。test(j) 檢查哲學家 jj 是否正在等待,以及左右兩側的鄰居是否都沒有在進食;符合條件時,便把 jj 的狀態設為 EATING,並透過 self[j].signal() 喚醒他。

因為哲學家編號沿逆時針方向遞增,(i+4) mod 5 等於 (i-1) mod 5,也就是哲學家 ii 的左鄰居。

解題方法

在 putdown(i) 中,哲學家 ii 放下筷子後,程式依序執行:

test((i+4) mod 5),test((i+1) mod 5)\text{test}((i+4)\bmod 5),\qquad \text{test}((i+1)\bmod 5)

第一個呼叫的參數是 j=(i−1) mod 5j=(i-1)\bmod 5,因此檢查的是 ii 的左鄰居 jj。test(j) 的判斷條件為:

  • jj 的左鄰居沒有在進食;
  • jj 本人處於 HUNGRY;
  • jj 的右鄰居沒有在進食。
🔒

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

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

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

Consider two one-bit ALU designs and a 32-bit ALU design for a 32-bit MIPS CPU design.

🖼️【此處有附圖,請對照原卷】

第 27 題

Which of the following statements is correct?

(A) The left figure is the most significant bit (MSB) ALU and the set signal comes from S2S2.
(B) The middle figure is the MSB ALU and the set signal comes from CarryOutCarryOut.
(C) The concept to realize sltslt is that subtraction is performed first and then the CarryOutCarryOut of the MSB ALU is the set signal that is connected to the least significant bit ALU.
(D) The set signal comes from the S1S1 of the ALU in the left figure.

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

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

這一題的完整詳解

核心觀念

本題考 最高有效位元(MSB)ALU 的辨識,以及 MIPS 的有號比較指令 slt 如何產生比較結果。

slt 先利用加法器執行二補數減法:

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

若 A<BA<B,結果設為 11;否則設為 00。比較結果由 MSB ALU 產生的 Set 訊號送至最低有效位元(LSB)ALU 的 Less 輸入,其餘位元的 Less 輸入皆為 00,因此最後輸出只有最低位元能為 11。

有號比較不能直接使用最高位元的進位輸出 CarryOut。若減法發生溢位,還須修正差值的符號:

Set=s31⊕Overflow\mathrm{Set}=s_{31}\oplus \mathrm{Overflow}

其中 s31s_{31} 是減法結果的最高位元。

解題方法

依原圖,左圖具有溢位偵測電路,S2S2 接加法器的和輸出,S1S1 接進位輸出;中圖則是一般位元 ALU。 右側的 32 位元 ALU 圖顯示,最下方的 ALU31 產生 Set,再回接最上方 ALU0 的 Less 輸入。

因此可從兩點判斷:

  1. **辨識 MSB ALU:**左圖具有溢位偵測與 Set 產生功能,對應右圖的 ALU31。
  2. **追蹤 Set 的來源:**左圖的 S2S2 是加法器的和位元,代表 MSB 的減法結果;
🔒

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

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

免費註冊

第 28 題

Which of the following statements is correct?

(A) The control signal setting to realize a sltslt instruction is: AInvert=1AInvert=1; BInvert=1BInvert=1; Operation=10Operation=10; CarryIn=1CarryIn=1.
(B) The control signal setting to realize a sltslt instruction is: AInvert=0AInvert=0; BInvert=1BInvert=1; Operation=11Operation=11; CarryIn=1CarryIn=1.
(C) The control signal setting to realize a subsub instruction is: AInvert=0AInvert=0; BInvert=1BInvert=1; Operation=00Operation=00; CarryIn=1CarryIn=1.
(D) The control signal setting to realize a subsub instruction is: AInvert=0AInvert=0; BInvert=1BInvert=1; Operation=10Operation=10; CarryIn=0CarryIn=0.

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

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

這一題的完整詳解

核心觀念

這題考 MIPS ALU 如何用控制訊號選擇邏輯運算、加法、減法與小於比較。兩個輸入反相控制訊號分別是 AInvert、BInvert;CarryIn 是最低位元加法器的輸入進位;Operation 選擇 ALU 的輸出功能。

減法可用二補數加法實現:

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

因此,執行減法時要反相 BB,並將最低位元的 CarryIn 設為 11。

解題方法

sub 的 ALU 控制設定為:

  • AInvert=0:不反相 AA。
  • BInvert=1:將 BB 反相。
  • CarryIn=1:補上二補數減法所需的 +1+1。
  • Operation=10:選擇加法器輸出,完成 A+B‾+1A+\overline{B}+1。

slt(set on less than)先以相同方式計算 A−BA-B,再由 ALU 的比較路徑將比較結果寫入輸出。

🔒

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

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

免費註冊

第 29 題

Which of the following statements is correct?

(A) The control signal setting to realize a bnebne instruction is: AInvert=0AInvert=0; BInvert=1BInvert=1; Operation=10Operation=10; CarryIn=1CarryIn=1.
(B) The control signal setting to realize a nornor instruction is: AInvert=1AInvert=1; BInvert=1BInvert=1; Operation=01Operation=01; CarryIn=0CarryIn=0.
(C) The control signal setting to realize a lwlw instruction is: AInvert=1AInvert=1; BInvert=1BInvert=1; Operation=10Operation=10; CarryIn=1CarryIn=1.
(D) The control signal setting to realize a swsw instruction is: AInvert=1AInvert=1; BInvert=1BInvert=1; Operation=00Operation=00; CarryIn=0CarryIn=0.

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

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

這一題的完整詳解

核心觀念

本題考兩種一位元 ALU 切片的控制訊號,以及 32 位元 ALU 如何組合成算術與邏輯運算。依題目所述的控制編碼:

  • Operation=00:AND
  • Operation=01:OR
  • Operation=10:加法
  • Operation=11:通常用於比較運算
  • AInvert、BInvert:分別控制是否反相輸入 AA、BB
  • CarryIn:加法器的進位輸入

減法可利用二補數表示法實現:

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

因此,執行減法時令 BInvert=1、CarryIn=1,再選擇加法器運算。

解題方法

逐一比對各指令需要的運算:

  • bne:計算 A−BA-B,再依結果是否非零決定是否分支。
  • nor:運算為 A∨B‾\overline{A\lor B},可利用德摩根定律寫成 A‾∧B‾\overline{A}\land\overline{B}。
  • lw、sw:計算基底暫存器加上位移量,屬於加法。

選項分析

(A) 正確。 bne 比較兩個暫存器是否不相等時,先計算 A−BA-B。設定 BInvert=1、CarryIn=1,可使加法器執行二補數減法;AInvert=0 保留 AA,Operation=10 選擇加法器結果。

🔒

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

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

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

Given that (1) memory space is 32-bit byte addressable, (2) main memory size is 2mm2^{mm} bytes, (3) page frame size is 2pf2^{pf} bytes, (4) cache size is 2cache2^{cache} bytes, and (5) cache block size is 2cb2^{cb} bytes.

第 30 題

The memory space available to a program is ____ bytes.

(A) 2322^{32}
(B) 2312^{31}
(C) 2mm2^{mm}
(D) 2mm−12^{mm-1}

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

這一題的完整詳解

核心觀念

「32-bit byte addressable」表示位址長度為 32 位元,而且每個位址對應 1 個位元組。程式可用的位址空間大小取決於位址能表示多少個不同位置,與實際主記憶體大小 2mm2^{mm}、頁框大小或快取大小無關。

解題方法

32 位元位址可表示 2322^{32} 種不同位址。每個位址指向 1 byte,因此程式的記憶體空間為:

232 bytes2^{32}\text{ bytes}

選項分析

🔒

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

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

免費註冊

第 31 題

The number of virtual pages is ____.

(A) 2mm2^{mm}
(B) 232−2mm2^{32-2mm}
(C) 232−cache2^{32-cache}
(D) 232−pf2^{32-pf}

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

這一題的完整詳解

核心觀念

虛擬頁(virtual page)是虛擬位址空間依頁面大小切分後的區塊。題目給定位址為 32 位元,代表虛擬位址空間共有 2322^{32} 個位元組;頁框大小為 2pf2^{pf} 位元組,因此每頁包含 2pf2^{pf} 個位元組。

解題方法

虛擬頁數等於虛擬位址空間大小除以每頁大小:

虛擬頁數=232 bytes2pf bytes=232−pf\text{虛擬頁數} = \frac{2^{32}\text{ bytes}}{2^{pf}\text{ bytes}} = 2^{32-pf}

因此正確選項為 (D)。主記憶體大小、快取大小與快取區塊大小不影響虛擬頁數。

選項分析

🔒

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

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

免費註冊

第 32 題

The page size is ____.

(A) 232/mm2^{32/mm}
(B) 2mm/2pf2^{mm/2^{pf}}
(C) 2pf2^{pf}
(D) 2pf/cb2^{pf/cb}

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

這一題的完整詳解

核心觀念

虛擬記憶體以「頁」(page)為單位,實體記憶體則切分成大小相同的「頁框」(page frame)。因此,頁的大小等於頁框的大小。

題目已知頁框大小為 2pf2^{pf} bytes,所以頁大小也是 2pf2^{pf} bytes。

解題方法

直接套用頁與頁框的定義:

page size=page frame size=2pf bytes\text{page size}=\text{page frame size}=2^{pf}\text{ bytes}

因此選項 (C) 正確。

選項分析

🔒

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

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

免費註冊

第 33 題

The size of the cache block tag in bits is ____ (choose the most proper one).

(A) ⌊32−cb⌋\lfloor 32-cb \rfloor
(B) 32−cache32-cache
(C) (32−cache)−⌊32−cb⌋(32-cache)-\lfloor 32-cb \rfloor
(D) 2(32−cache)−2≤⌊32−cb⌋2^{(32-cache)-2}\leq\lfloor 32-cb \rfloor

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

這一題的完整詳解

核心觀念

記憶體位址通常分成「標籤(tag)」、「索引(index)」與「區塊內位移(block offset)」三部分:

位址位元數=tag 位元數+index 位元數+block offset 位元數\text{位址位元數} = \text{tag 位元數} + \text{index 位元數} + \text{block offset 位元數}

題目給定 32 位元組位址,快取大小為 2cache2^{cache} bytes,快取區塊大小為 2cb2^{cb} bytes。依照選項採用的直接對映快取假設,可求出各欄位的位元數。

解題方法

區塊大小是 2cb2^{cb} bytes,因此區塊內位移需要 cbcb 個位元。快取中的區塊數為:

2cache2cb=2cache−cb\frac{2^{cache}}{2^{cb}}=2^{cache-cb}

直接對映快取的每個區塊都有一個索引位置,因此索引需要 cache−cbcache-cb 個位元。代入位址分解式:

tag 位元數=32−(cache−cb)−cb=32−cache\text{tag 位元數} =32-(cache-cb)-cb =32-cache

選項分析

🔒

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

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

免費註冊

其他考古題