115 年 國立陽明交通大學資訊工程學系碩士班《計算機系統》
第 1 題
Regarding dynamic loading, which of the following statements are TRUE?
(A) In dynamic loading, a routine is not loaded into the main memory until it is called; all routines are kept on disk in a relocatable load format until required.
(B) Dynamic loading typically offers better memory-space utilization than static loading because routines that are never called (such as large, infrequently used error-handling routines) are never loaded into memory.
(C) Dynamic loading strictly requires special support from the complex kernel process scheduling function; it is impossible for user programs to implement this method using standard libraries alone.
(D) Compared to dynamic loading, static loading generally results in faster program startup times for large applications because the entire program is loaded into memory at once, avoiding runtime overheads during execution.
登入後即可作答並保存紀錄。
核心觀念
動態載入(dynamic loading)是指程式執行時,某個副程式只有在第一次被呼叫時才載入主記憶體。尚未呼叫的副程式可以繼續留在磁碟上,因此可節省記憶體,特別是程式包含大型、低頻使用的例外處理或錯誤處理程式時。
靜態載入(static loading)則是在程式開始執行前,將程式所需的部分載入記憶體。兩者的主要差異在於載入時機;動態載入不必仰賴作業系統核心的排程功能,使用者程式也能透過程式庫實作。
解題方法
逐項檢查敘述是否符合動態載入的定義,並分清楚「節省記憶體」與「啟動速度」這兩種不同效益。動態載入的核心特徵是「呼叫時才載入」,但這不代表每次呼叫都要重新載入;通常只在第一次需要時載入。
選項分析
第 2 題
Which of the following statements best distinguishes software traps from hardware interrupts in terms of their origin, execution context, and privilege transition?
(A) Handling Timing: Hardware interrupts are typically recognized and serviced only at instruction boundaries (i.e., after the current instruction retires), whereas software traps (specifically faults like Page Faults) are recognized and serviced immediately during the execution of the instruction.
(B) Masking Capability: The operating system can use the Interrupt Flag (e.g., IF in x86) to mask (ignore) “Divide-by-Zero” and “Page Fault” software traps to ensure atomicity within critical sections.
(C) Synchronicity: Hardware interrupts are asynchronous events triggered by external devices (independent of the CPU clock), whereas software traps are synchronous events tied directly to the execution of a specific instruction.
(D) Event Nature: Software traps strictly indicate erroneous program behavior (e.g., illegal memory access), whereas hardware interrupts indicate normal system events; therefore, legitimate operating system service requests (System Calls) are never implemented using the trap mechanism.
登入後即可作答並保存紀錄。
核心觀念
硬體中斷與軟體陷阱(software trap)主要依事件來源與是否同步於目前指令來區分:
- 硬體中斷由外部裝置或計時器等事件觸發,與目前正在執行哪一條指令無關,因此屬於非同步事件。處理器通常在指令完成、到達指令邊界時辨識並轉入中斷處理程序。
- 軟體陷阱/例外由目前指令的執行所引發,屬於同步事件。例如除以零、非法指令、頁面錯誤;系統呼叫也可透過軟體陷阱進入作業系統。
- 事件發生後,處理器會依架構保存必要狀態並轉入對應的處理程序。若事件要求更高的特權層級,處理器會切換至核心態;這種特權轉移本身不代表事件一定是硬體中斷或錯誤。
解題方法
先看事件的來源與同步性:外部裝置引發的是非同步硬體中斷;由指令執行引發的是同步陷阱或例外。再檢查中斷遮罩與事件用途:一般中斷旗標可遮蔽可遮罩的硬體中斷,但不能因此屏蔽除以零或頁面錯誤等同步例外;
第 3 題
Regarding the necessity, performance, and structure of multi-level page tables compared to single-level page tables, which of the following statements are TRUE?
(A) A primary necessity for multi-level design in modern architectures (e.g., 64-bit) is that a linear single-level page table would require a huge, but not contiguous, block of kernel memory, which is often impossible to allocate.
(B) In terms of memory consumption, a multi-level page table always consumes less physical memory than a single-level page table, regardless of whether the process’s virtual address space is sparse or fully populated (dense).
(C) Regarding address-space sparsity, multi-level page tables save memory by allowing the operating system to avoid allocating inner-level page tables for invalid (unused) regions of the virtual address space.
(D) In terms of memory access time (assuming a TLB miss), the multi-level page table structure introduces a performance overhead compared to a single-level table, as the MMU must perform multiple memory references to traverse the hierarchy (e.g., directory → table → frame).
登入後即可作答並保存紀錄。
核心觀念
單層頁表以一張線性表記錄虛擬頁面到實體頁框的對應。若虛擬位址空間很大,頁表就需要許多表項;即使大量虛擬位址區域未使用,線性表仍須涵蓋整個位址範圍。
多層頁表把這張表拆成階層。上層表項指向下層頁表,作業系統可只配置實際需要的下層頁表。這能減少稀疏位址空間的頁表記憶體用量,但會增加位址轉譯時的存取次數。
解題方法
逐項檢查兩個面向:
- 記憶體用量:比較稀疏與密集位址空間下,階層式配置是否能省下未使用區域的頁表。
- 存取時間:在 TLB 未命中時,比較單層查表與多層逐級查表所需的記憶體參照次數。
選項分析
(A) 錯誤。
64 位元架構的單層頁表確實可能非常龐大,這是採用多層頁表的重要原因之一。不過,選項稱其為「巨大但不連續的記憶體區塊」,並以難以配置作為理由,敘述不當:不連續的記憶體可由多個實體頁組成;若談線性頁表的連續配置困難,應是指需要巨大且連續的區塊。
第 4 題
Regarding the behavior of fork() and exec() system calls in a multithreaded process (specifically under POSIX standards), which of the following statements are TRUE?
(A) When fork() is invoked by a thread in a multithreaded process, the resulting child process contains duplicates of all threads that were running in the parent process at the time of the call.
(B) If a thread other than the one calling fork() holds a lock (e.g., a mutex) at the moment fork() is called, that lock will exist in the child process in a locked state, but the thread holding it will not exist in the child to unlock it, leading to potential deadlocks if the child tries to acquire this lock.
(C) It is generally unsafe to call complex library functions (like printf or malloc) in the child process between fork() and exec() because these functions may rely on internal locks that were left in an inconsistent state during the fork.
(D) The exec() system call allows the child process to retain the memory space and thread context of the parent process while simply resetting the Program Counter (PC) to the beginning of the main() function.
登入後即可作答並保存紀錄。
核心觀念
這題考查多執行緒程序呼叫 fork() 與 exec() 時,程序、執行緒及記憶體的變化。
fork() 建立子程序。若父程序有多個執行緒,子程序只保留呼叫 fork() 的那個執行緒;其他執行緒不會在子程序中出現。不過,子程序會複製父程序當下的記憶體內容,因此其他執行緒持有的鎖也可能以「已上鎖」的狀態留在子程序裡。
exec() 則以新程式映像取代目前程序的映像,包含原有的程式碼、資料與堆疊;它不是只重設程式計數器。
解題方法
逐一檢查各選項是否符合上述兩個系統呼叫的行為。特別注意:fork() 複製的是程序的記憶體狀態,但不會複製所有執行緒;exec() 會替換程序映像。
選項分析
(A) 錯誤。
多執行緒程序呼叫 fork() 後,子程序只包含呼叫 fork() 的執行緒,不會包含父程序中的所有執行緒。父程序本身則繼續保有原來的執行緒。
第 5 題
Regarding virtual memory management techniques, specifically Thrashing, Working-Set Model, Page Replacement Algorithms, and Copy-on-Write (COW), which of the following statements are TRUE?
(A) A classic symptom of thrashing is low CPU utilization. This occurs because processes spend the majority of their time waiting for the paging device (I/O), which often misleads the standard OS scheduler into increasing the degree of multiprogramming, thereby worsening the thrashing.
(B) Belady’s anomaly refers to the phenomenon where increasing the number of available page frames results in an increase in the number of page faults. This anomaly can occur in the FIFO algorithm but is mathematically proven to be impossible in LRU (Least Recently Used), which belongs to the class of stack algorithms.
(C) When fork() is executed with Copy-on-Write enabled, the parent and child processes share the same physical pages. To detect when a copy is needed, these shared pages are initially marked as read-write in the page table so that the hardware allows the write to proceed immediately without OS intervention.
(D) The Working-Set Model prevents thrashing by estimating the current locality of each process. If the sum of the working-set sizes of all active processes exceeds the total number of available frames, the operating system selects a process to suspend (swap out) to release frames.
登入後即可作答並保存紀錄。
核心觀念
本題考查四個虛擬記憶體觀念:
- Thrashing(顛簸):系統花大量時間處理缺頁與磁碟 I/O,真正執行程式的時間減少,CPU 使用率可能偏低。
- Working-Set Model(工作集模型):以最近一段時間內使用過的頁面估計程序目前的區域性需求,避免同時執行的程序總需求超過實體記憶體容量。
- Belady’s anomaly(Belady 異常):增加頁框數後,缺頁次數反而增加;FIFO 可能發生,LRU 等堆疊演算法不會發生。
- Copy-on-Write(寫入時複製,COW):
fork()後父子程序先共用實體頁面;共用頁面須設為唯讀,任一方嘗試寫入時觸發保護錯誤,再由作業系統複製頁面。
解題方法
逐項檢查敘述是否符合上述定義。特別要注意:COW 的關鍵不是「寫入可直接通過」,而是「先以唯讀保護頁面,寫入時才觸發複製」;Belady 異常則要確認其定義及哪些演算法具有堆疊性質。
選項分析
(A) 正確。
顛簸時,程序頻繁缺頁,CPU 常在等待分頁裝置完成 I/O,因此 CPU 使用率會下降。若作業系統只看到低 CPU 使用率,可能誤以為系統需要更多可執行程序,於是提高多元程式度;更多程序競爭有限頁框,會讓缺頁更頻繁,進一步加重顛簸。
第 6 題
Which of the following statements about CPU scheduling are correct?
(A) The turnaround time of the non-preemptive Shortest-Job-First (SJF) scheduling remains even when the arrival rate of jobs varies.
(B) The turnaround time of the SJF is always shorter than that of the First-In-First-Out (FIFO) scheduling when all jobs arrive in the system simultaneously.
(C) We define the response time as the time from when the job arrives in a system to the first time it is scheduled for execution. The average response time of the round robin (RR) scheduling is shorter than that of preemptive SJF scheduling.
(D) We can periodically increase the priority of all jobs in the system to mitigate the starvation problem exhibited in Multi-Level Feedback Queue (MLFQ) scheduling.
登入後即可作答並保存紀錄。
核心觀念
- 周轉時間(turnaround time):從工作到達系統,到工作完成所經過的時間。若工作 的到達時間為 、完成時間為 ,則
平均周轉時間為所有 的平均。 - 回應時間(response time):從工作到達系統,到它第一次取得 CPU 執行的時間。
- SJF 依工作長度由短至長排程;可搶先 SJF 常以最短剩餘時間優先(SRTF)實作。RR 則讓就緒工作依序各執行一個時間片。
- MLFQ 以多個優先權佇列動態調整工作優先權。若要避免飢餓,必須確保低優先權工作能逐步越過高優先權工作。
解題方法
逐項判斷敘述是否符合排程指標的定義與演算法特性。特別要分清楚:SJF 對同時到達的工作能最佳化平均周轉時間;RR 的設計重點則是讓多個工作較快輪流取得第一次執行機會。
選項分析
(A) 錯誤。
非搶先 SJF 的周轉時間不會在到達率改變時保持不變。到達時間會影響工作何時進入就緒佇列,也會影響 CPU 是否空閒,以及後續工作的等待時間。即使 SJF 一律選擇當下就緒工作中最短者,改變工作到達時刻仍可能改變排程順序與完成時間,因此周轉時間會受影響。
(B) 正確。
所有工作同時到達時,周轉時間等於完成時間。SJF 將工作按執行時間由短至長排列,可使平均周轉時間最小。
第 7 題
Atomicity violation bugs occur when multiple operations intended to run as an indivisible (atomic) unit are interrupted by another thread in concurrent programs. The atomicity violation bugs result in the desired serializability among multiple memory accesses being violated, leading to lost updates. Please choose the correct atomicity violation bug code pattern(s) below.
(A)
static int i = 0;
static object a, b = default;
var tid1 = Task.Run(() => {
lock(a) { i++; }
});
var tid2 = Task.Run(() => {
lock(b) { i++; }
});
Task.WhenAll(tid1, tid2); print(i);
(B)
static pthread_cond_var WorkDone = PTHREAD_COND_INIT;
void main() {
pthread_t id = null;
pthread_create(&id, NULL, &fun, NULL);
pthread_wait(&WorkDone);
}
void fun() { pthread_signal(&WorkDone); }
(C)
static int i = 0;
var tid1 = Task.Run(() => {
if (atomic_load(&i) == 0) {
atomic_add(&i, 1);
}
});
var tid2 = Task.Run(() => {
if (atomic_load(&i) == 0) {
atomic_add(&i, 1);
}
});
Task.WhenAll(tid1, tid2); print(i);
(D)
static long int i = 101;
var tid1 = Task.Run(() => {
i++;
});
var tid2 = Task.Run(() => {
print(i);
});
Task.WhenAll(tid1, tid2);
登入後即可作答並保存紀錄。
核心觀念
Atomicity violation(原子性違反)是指一段原本應視為不可分割的操作,被其他執行緒插入操作,導致共享資料不符合預期的序列化結果。要特別分辨:個別指令是 atomic,不代表由多個指令組成的整段邏輯也具有原子性。
解題方法
圖中第 7 題列出四種並行程式:兩個不同鎖保護同一變數、條件變數的 signal/wait、由 atomic 操作組成的檢查後更新,以及未同步的遞增與讀取。逐一檢查共享資料是否受到一致的同步保護,以及一連串操作是否可能被另一執行緒插入。
選項分析
-
**(A) 正確。**兩個執行緒都修改共享變數
i,但分別鎖住a與b。不同的鎖彼此不互斥,因此兩個i++仍可能交錯。i++本身包含讀取、加一、寫回;若兩個執行緒都讀到相同舊值,最後可能只增加一次,形成 lost update。要保護同一共享資料,兩邊必須使用同一把鎖。 -
**(B) 錯誤。**條件變數的
signal若發生在等待者進入wait之前,通知可能遺失,造成等待者一直等不到訊號;正確使用條件變數還需要搭配互斥鎖與受保護的條件判斷。
第 8 題
The spin lock ensures the correctness of concurrent programs on multiple processors. Please choose the correct spin-lock implementation(s) and usage(s) including the Test-And-Set, Compare-And-Swap, Load-Linked and Store-Conditional, and Fetch-And-Add instructions. Note that LoadLinked() and StoreConditional(), respectively, perform Load-Linked and Store-Conditional operations.
(A)
int TestAndSet(int *old_ptr, int new) {
int old = *old_ptr;
*old_ptr = new;
return old;
}
(B)
int CompareAndSwap(int *ptr, int expected, int new) {
int original = expected;
if (*ptr == expected)
original = new;
return original;
}
(C)
void lock(lock_t *lock) {
while (1) {
if (LoadLinked(&lock->flag) == 1) return;
while (StoreConditional(&lock->flag, 1) == 1);
}
}
(D)
int FetchAndAdd(int *ptr) {
int old = *ptr;
*ptr = old + 1;
return *ptr;
}
登入後即可作答並保存紀錄。
核心觀念
自旋鎖依賴「不可分割的讀取-修改-寫入」操作,讓多個處理器競爭同一個鎖變數時,最多只有一個處理器能成功取得鎖。常見原子指令包括 Test-And-Set、Compare-And-Swap、Load-Linked/Store-Conditional(LL/SC)及 Fetch-And-Add(FAA)。
判斷程式時要確認兩件事:操作是否具原子性,以及回傳值是否符合該指令的定義。自旋鎖通常以 0 表示未上鎖、1 表示已上鎖。
解題方法
逐一檢查各選項的讀寫順序與回傳值:
- Test-And-Set 應原子地回傳舊值,並寫入新值。
- Compare-And-Swap 應回傳原本的記憶體值;只有原值等於預期值時才更新。
- LL/SC 應先讀取鎖,再嘗試條件式寫入;只有寫入成功者取得鎖。
- FAA 應原子地把記憶體值加一;本題公布答案採用回傳更新後數值的寫法。
選項分析
(A) 正確。
此函式先保存舊值,再寫入新值,最後回傳舊值,符合 Test-And-Set 的操作語意:
在自旋鎖中,若原子地呼叫 TestAndSet(&lock->flag, 1),回傳 0 的處理器可取得鎖;回傳 1 則表示鎖已被其他處理器持有,繼續自旋。這裡的正確性以 Test-And-Set 作為原子指令為前提,不能把程式中的一般讀寫當成多處理器環境下的原子操作。
第 9 題
The Linux cat command opens the file for reading. On Linux, the strace tool can dump the trace of every system call made by the cat Linux command shown below. Please choose the correct description(s) for system calls used by the cat Linux command.
prompt> strace cat hello
...
open("hello", O_RDONLY | O_LARGEFILE)
read(3, "helloworld\n", 4096)
write(X, "helloworld\n", 11)
helloworld
read(3, "", 4096)
close(3)
...
(A) The return value of the first open system call is 3.
(B) The return value of the first read system call is 11.
(C) The first argument (X) of the write system call represents the file descriptor and the value of X is 1.
(D) The return value of the second read system call is 0.
登入後即可作答並保存紀錄。
核心觀念
Linux 系統呼叫會以檔案描述符(file descriptor, fd)識別開啟的檔案或輸出串流。一般程序啟動時,標準輸入、標準輸出、標準錯誤分別使用 fd 、、;新開啟的檔案通常取得當下最小可用的 fd。
read(fd, buffer, count) 最多讀取 count 個位元組,回傳實際讀到的位元組數;讀到檔案結尾時回傳 。write(fd, buffer, count) 的第一個參數是目的檔案描述符。
解題方法
依照系統呼叫的執行順序判讀:
cat開啟hello,其後以 fd 讀取,因此這次open回傳的檔案描述符是 。- 第一次
read讀到"helloworld\n"。字串中helloworld有 個字元,換行符號\n再占 個位元組,所以回傳 。 cat將讀到的內容寫至標準輸出。
第 10 題
The hard drive (disk) has become the main form of persistent data storage in computer systems. In the disk, the motor spins the platters around at a constant rate. The rate of hard drive rotation is measured in Rotations Per Minute (RPM). Please choose the correct description(s) about the performance of disks below.
(A) Each rotation takes 6 milliseconds (ms) when the RPM of this disk is 10,000.
(B) When the transfer rate of a disk is 100 MB/second, transferring a 1024 KB block takes 10 milliseconds (ms) to complete.
(C) The SCAN disk scheduler is invented to shorten the seek time of the disk.
(D) The SCAN disk scheduler can resolve the starvation problem shown in the Shortest Seek Time First (SSTF) disk scheduler when a steady stream of requests is always directed to the inner track of the disk, where the head currently is positioned.
登入後即可作答並保存紀錄。
核心觀念
磁碟存取時間主要包含尋道時間、旋轉延遲與資料傳輸時間。這題考查轉速與旋轉時間的換算、傳輸率的計算,以及磁碟排程演算法如何安排磁頭移動。
- 轉速為 RPM 時,每轉一圈的時間為:
- 傳輸時間為:
- SCAN(電梯演算法)讓磁頭沿固定方向掃描磁柱,途中服務請求,到達端點後再反向掃描,以減少不必要的磁頭移動並避免 SSTF 的飢餓問題。
解題方法與選項分析
(A) 正確。
轉速為 RPM,因此每分鐘轉 圈,每圈所需時間為:
第 11 題
Which of the following statements are true?
(A) The metric of ops/sec is not the absolute performance metric for AI accelerators; instead, the metric of tokens/sec is a good indicator for LLM inference.
(B) The CPU performance metric MIPS is not a fair indicator because it does not consider the complexity of machine instructions. A machine instruction set of short and fast instructions tends to have higher MIPS.
(C) NVIDIA NVLink and AMD Infinity Fabric are used to improve the data transfer rate between chips as an LLM model training and inference cannot be conducted within a single AI accelerating chip.
(D) Data center computing resources consistently operate at high utilization levels due to rapidly increasing demand, while utilization imbalances across data centers can be effectively mitigated through network-enabled demand redistribution.
登入後即可作答並保存紀錄。
核心觀念
本題考查 AI 加速器與 CPU 的效能指標、晶片間互連,以及資料中心資源利用率。
- **吞吐量(throughput)**表示單位時間完成的工作量。不同工作負載的操作內容與成本不同,因此單看 ops/sec(每秒操作數)未必能公平比較 AI 加速器。對 LLM 推論而言,每秒生成的 token 數(tokens/sec)是較貼近使用體驗的指標,但仍須搭配模型大小、批次大小與延遲等條件解讀。
- MIPS 是每秒執行的機器指令數,沒有反映指令複雜度,也不等同於程式完成速度。
- 晶片間互連用來提高多顆處理器或加速器之間的資料傳輸能力。大型模型的訓練與推論常因模型或運算需求而分散到多顆加速器。
- 資料中心利用率會受負載變化、地點、網路與資源配置等因素影響,不能僅由需求成長推論所有資料中心都持續高利用率,也不能假設跨資料中心的需求轉移可消除利用率不均。
解題方法
逐項辨認敘述是否把「效能指標」與「實際工作負載」相連,或是否將特定技術的用途及適用條件說得過於絕對。尤其要留意選項中的「不能在單一晶片完成」、「持續高利用率」等概括性敘述。
選項分析
第 12 題
Which of the following statements are true?
(A) The machine instruction add s2, n2n$ can be included in the instruction set without increasing the clock period.
(D) The key idea of lazy linkage is to use an indirection table that initially holds the address of a linker/loader resolver for a DLL routine and is later updated with the address of the loaded DLL routine, making subsequent calls more efficient.
登入後即可作答並保存紀錄。
核心觀念
本題考查 MIPS 指令與 CPU 設計原則、基本區塊(basic block)、多週期處理器的時脈設計,以及動態連結的延遲繫結(lazy linkage)。
判斷時要分清楚:指令格式與暫存器數量對應的設計原則、機器碼基本區塊與程式語言區塊的用途,以及指令執行時間和時脈週期的差別。
解題方法
逐項檢查敘述中的定義與因果關係:
- 指令格式是否體現規則性,暫存器數量是否涉及「較小較快」。
- 基本區塊的控制流程定義是否正確,及其用途是否被誤說成 C 語言區塊的變數生命期。
- 多週期 CPU 是否能將較長的操作拆成多個時脈週期。
- 延遲繫結是否透過間接表格,在首次呼叫時解析、之後直接呼叫已載入的函式。
選項分析
(A) 正確。
`add s2,
第 13 題
Consider the above ALU design. The control signals are grouped as (Ainvert, Binvert, Operation[1], Operation[0]). Which of the following statements are true?
🖼️【此處有附圖,見下方】
(A) The control signal group (1, 1, 0, 1) performs an instruction.
(B) The following code sequence performs an overflow detection for unsigned addition ():
addu t1, t3, zero;
sltu t3, t3, $zero, Overflow
(C) The Set signal is introduced to implement the set-less-than instruction and corresponds to the sum output of ALU31.
(D) The control signal group (0, 1, 1, 1) performs a set-less-than instruction.
登入後即可作答並保存紀錄。
核心觀念
此題考 1-bit ALU 的控制訊號如何選擇邏輯與算術運算,以及無號加法溢位與 sltu 的判斷方式。依 ALU 圖,控制訊號依序為 ;32 個 1-bit ALU 串接形成 32-bit 結果,Zero 由結果各位元合併判斷,Set 則由最高位 ALU 的結果送回最低位 ALU,供 slt 使用。
解題方法
先由控制訊號解讀輸入是否反相,再看 Operation 選出的邏輯或算術功能。圖中 Operation = 01 選 OR、Operation = 11 選 SLT;若 、,則 OR 的兩個輸入都先反相。程式片段則把無號溢位條件轉成大小比較,再檢查分支是否在該條件成立時執行。
選項分析
(A) 正確。 訊號 會先將兩個輸入反相,再執行 OR:
依圖中選項的反相符號,這是 運算。
第 14 題
Which of the following statements are true?
(A) Consider the above ALU design and a multiplication of . The value of the Remainder register is after three iterations of multiplication is conducted.
(B) Consider the same ALU design and now a division of using the restoring scheme is conducted. The value of the Remainder register is after four iterations of division is conducted. Note that the shift operation is performed at the end of each iteration rather than at the beginning.
(C) Consider the 5-bit non-restoring division algorithm that performs shift-left operation at the end of each iteration rather than at the beginning. The algorithm requires 6 but not 5 iterations to obtain correct quotient.
(D) Consider a multiplication of applying the Booth algorithm. This multiplication requires two additions and two subtractions.
🖼️【此處有附圖,見下方】
登入後即可作答並保存紀錄。
核心觀念
圖中是共用 10 位元 ALU 與 10 位元 Remainder 暫存器的乘除法資料路徑;Divisor 為 5 位元,控制器可令暫存器左移、右移或寫入。乘法用移位加法追蹤部分乘積;restoring division 在試減結果為負時還原;non-restoring division 則依部分餘數的正負決定下一步加減;Booth 演算法依相鄰乘數位元決定加、減或不動作。
解題方法
(A) 將乘數放入 Remainder 暫存器低 5 位,逐輪檢查最低位;最低位為 1 時,將被乘數加到高 5 位,再將整個暫存器右移。
初值為 ,被乘數為 :
| 輪次 | 加法與右移後的 Remainder |
|---|---|
| 1 | |
| 2 | |
| 3 | 最低位為 0,右移: |
三輪後的值是 ,不是選項所說的 ,所以 (A) 錯。
(B) Restoring division 每輪將試減結果與除數比較:差為負便還原,否則保留差值並設定商位。
第 15 題
Consider a 16-bit Floating-Point format following IEEE Std 754 with one signed bit, 4-bit exponent and 11-bit fraction. . Which of the following statements are true?
(A) The maximum positive FP number in this format is .
(B) The smallest positive de-normalized number is .
(C) To ensure the exponent is unsigned, the bias should be 15.
(D) Floating-point addition requires aligning the binary points by shifting the operand with the smaller exponent; otherwise, shifting the operand with the larger exponent could make its fraction excessively large and result in overflow, while excessive shifting of the smaller-exponent operand may cause its fraction to be truncated.
登入後即可作答並保存紀錄。
核心觀念
浮點數的指數欄位採用偏移表示法。若指數欄位有 位,IEEE 754 的偏移值為
本題有 4 位指數,因此 。指數欄位全為 與全為 時有特殊用途:全 表示非正規化數或帶正負號的零;全 表示無窮大或 NaN。一般正規化數的指數欄位範圍為 至 。
解題方法
先求出偏移值,再分別依 IEEE 754 的指數欄位規則計算最大正規化數與最小正非正規化數。浮點數相加時,則先把兩數的指數調成相同,再對齊尾數進行加法。
選項分析
(A) 正確。 最大有限正數的指數欄位是 ,不是保留給無窮大與 NaN 的 。因此無偏移指數為 。尾數欄位全為 時,數值為
與選項相符。
第 16 題
The following statements describe three pairs of pipelined processors. In each pair, the processors are identical except for the specified feature. In all cases, the processors execute the same compiled program. Ignore differences in execution time, pipeline stalls, and throughput. Consider only whether the processors may produce different architectural results.
In Case A, processor A resolves data hazards using interlocks, while processor B uses full bypassing.
In Case B, processor A handles control hazards by stalling the pipeline until the branch target is known. Processor B uses a “predict-not-taken” scheme and flushes the pipeline if the branch is taken.
In Case C, processor A has a single memory port shared between instruction fetch and data access, while processor B has no structural hazards.
(A) Case A may produce different architectural results if a load instruction is immediately followed by an instruction that consumes the loaded value.
(B) Case B may produce different architectural results because Processor B may speculatively execute instructions that Processor A does not.
(C) Case C may produce different architectural results if an instruction fetch is delayed by a data memory access, causing a different ordering of memory accesses as observed architecturally.
(D) None of the cases will produce different architectural results, since all differences are purely microarchitectural.
登入後即可作答並保存紀錄。
核心觀念
管線處理器可以用不同的微架構方法處理資料相依、控制相依與結構相依。只要各方法都正確維持指令的架構語意,程式完成後可觀察的暫存器與記憶體結果就相同。
判斷本題的關鍵,是分清楚「指令何時執行」和「指令是否改變架構狀態」:停頓、轉送、預測與清除管線會改變執行過程;只有已提交的指令才會形成架構結果。
解題方法
逐案檢查處理器採用的機制是否保留正確的指令值與執行順序:
- 資料相依處理必須讓消費者取得生產者寫出的正確值。
- 分支預測錯誤時,錯誤路徑上的指令不得提交架構狀態。
- 結構衝突造成的停頓只延後指令執行,不改變程式的架構順序。
三案都符合上述條件,因此兩種處理器執行同一程式時,架構結果一致。
選項分析
(A) 錯誤。
載入指令後緊接著使用載入值的指令,確實有資料相依。使用互鎖的處理器會在資料尚未可用時停頓;使用完整旁路的處理器則會在值可轉送時直接傳給後續指令。兩者採取不同的管線安排,但都讓消費者使用載入指令產生的正確值,因此不會造成不同的架構結果。
第 17 題
A cache designer considers modifying a cache while keeping all parameters fixed except for the single change described. Assume a conventional set-associative cache with Least Recently Used (LRU) replacement. Which of the following statements is (are) correct?
(A) Doubling the cache line size while keeping cache capacity and associativity fixed strictly reduces the number of tag entries that must be compared on each cache access.
(B) Doubling the cache associativity while keeping cache capacity and line size fixed doubles the total number of tag entries in the cache.
(C) Doubling the capacity of a direct-mapped cache tends to reduce conflict misses but has minimal effect on compulsory misses.
(D) Doubling the cache line size tends to reduce compulsory misses by exploiting spatial locality and can increase conflict misses, while typically increasing the miss penalty.
登入後即可作答並保存紀錄。
核心觀念
快取容量可表示為:
其中 是快取容量、 是快取行數、 是每條快取行的大小。若為組相連快取,則:
是組數, 是相連度,也就是每組的快取行數。每次存取會依索引選出一組,並比較該組內 個標籤。
快取未命中常分為強制未命中、衝突未命中與容量未命中。強制未命中來自首次存取資料;衝突未命中則與多個記憶體區塊競爭同一組有關。
解題方法
逐一辨認各選項改變了哪個參數,再依快取容量公式判斷快取行數、組數或相連度如何變化。特別要區分「每次存取要比較的標籤數」與「快取中標籤項目的總數」:前者由相連度決定,後者由快取行數決定。
選項分析
(A) 錯誤。
相連度固定時,每次存取要比較的標籤數就是固定的相連度。加倍快取行大小、但維持容量與相連度不變,會使快取行數減半、組數減半;
第 18 題
A byte-addressable machine uses 36-bit virtual addresses and 30-bit physical addresses. To achieve high performance, the bits used to index into a physical cache set must be obtainable without performing virtual-to-physical address translation through the TLB. The cache block size is fixed at 64 bytes. Which of the following statements is (are) correct?
(A) Assuming a page size of bytes and an 8-way set-associative physically tagged cache, the maximum physical cache size that satisfies the above constraint is 32 KB.
(B) If the cache block offset is contained within the page offset, then cache indexing does not require virtual-to-physical address translation.
(C) Given a page size of bytes and a physical cache size of bytes, the minimum cache associativity required to avoid virtual-to-physical address translation during cache indexing is 32.
(D) If a -byte direct-mapped physical cache is used, the minimum page size that supports this cache configuration without requiring address translation for cache indexing is bytes.
登入後即可作答並保存紀錄。
核心觀念
實體索引快取的組別索引位元若要在 TLB 位址轉譯前取得,必須全部落在虛擬位址與實體位址共用的「頁內位移」中。若頁面大小為 bytes、快取區塊大小為 bytes,則區塊位移占 位;可供組別索引使用的位元最多為 位。
設快取容量為 、相連度為 ,則組數為
因此,免經 TLB 即可索引的條件為
也就是組別索引位元加區塊位移位元不能超出頁內位移。
解題方法
本題區塊大小固定為 bytes,所以區塊位移占 位。頁面大小為 bytes 時,頁內位移共 位,扣除區塊位移後,組別索引最多可用 位,也就是最多 組。
選項分析
-
**(A) 錯誤。**頁面大小為 bytes、相連度為 時,最多有 組,因此最大快取容量為
並非 。
第 19 題
Which of the following statements about branch prediction and conditional execution are true?
(A) The Branch Target Buffer (BTB) is typically accessed during the instruction decode stage to enable early redirection.
(B) Indirect branches, such as those used in switch statements, are generally easier to predict than conditional branches because their targets remain fixed once the branch outcome has been resolved.
(C) The 2-bit dynamic branch prediction scheme improves prediction accuracy primarily by exploiting global branch history and correlations among nearby branches.
(D) Programs that use the CSEL instruction in ARMv8 architecture can potentially reduce the number of conditional branch instructions by replacing control flow with conditional data selection.
登入後即可作答並保存紀錄。
核心觀念
分支預測器在處理器取指時預測控制流程,目標是減少分支造成的管線停頓。分支目標緩衝器(Branch Target Buffer, BTB)快取分支指令的目標位址;動態分支預測則依據過去的分支結果預測下一次的分支方向。
條件執行則可把部分控制流程改寫成條件式資料操作。例如 ARMv8 的 CSEL 會依條件選擇兩個來源之一,寫入目的暫存器,因而在適用情況下以資料選擇取代條件分支。
解題方法
逐項檢查敘述中的關鍵點:BTB 通常在哪個管線階段查詢、間接分支的目標是否固定、2-bit 預測器使用哪種歷史資訊,以及 CSEL 是否能用資料選擇取代控制流程。
選項分析
(A) 錯誤。 BTB 通常在取指階段(Instruction Fetch, IF)查詢,並與取指同時進行;若預測為分支,處理器就能及早改變取指位址。解碼階段不是典型的 BTB 查詢時機,因為等到解碼才查詢會延後重新導向。
第 20 題
Consider two compute systems, Machine A and Machine B, designed to accelerate linear-algebra workloads. Machine A can issue 3 multiply operations per cycle and sustains a memory bandwidth of 0.1 words per cycle. Machine B can issue 1 multiply operation per cycle and sustains a memory bandwidth of 0.5 words per cycle. Both machines have a multiplier latency of 1 cycle and operate at the same clock frequency.
Assume the following throughout this problem: instructions execute in program order; in each cycle, all multiplications whose dependencies are satisfied are issued, up to the number of available multipliers; only multiplications and loads from main memory incur cost; load latency is fully hidden once data is available; all kernels execute in steady state on large inputs; results are kept on-chip and are not written back to main memory; and at any time at most one kernel is executing on a machine.
Consider the following kernels:
- Matrix–vector multiplication of an matrix with an -element vector.
- Matrix–matrix multiplication of two matrices.
Which of the following statements are correct?
(A) The operational intensity of matrix–vector multiplication increases linearly with , while the operational intensity of matrix–matrix multiplication increases quadratically with .
(B) For sufficiently large , matrix–vector multiplication is memory-bandwidth bound on both machines, and Machine B achieves higher performance due to its higher memory bandwidth.
(C) For sufficiently large , matrix–matrix multiplication becomes compute-bound on Machine A, allowing it to outperform Machine B despite having lower memory bandwidth.
(D) The roofline model alone is insufficient to compare the performance of the two machines on these kernels, because instruction ordering and multiplier latency dominate performance.
登入後即可作答並保存紀錄。
核心觀念
Roofline 模型以運算強度與兩種硬體上限估算效能:
其中 是每週期可發出的乘法數, 是每週期可載入的字數, 是每載入一個字所執行的乘法數。本題只計乘法與主記憶體載入,且結果不寫回主記憶體。
解題方法
矩陣向量乘法需做 次乘法,並載入 個矩陣元素。向量元素若能重複使用,另需載入 個字,因此
即使向量重複載入,運算強度仍是常數階,不會隨 線性增加。
矩陣矩陣乘法需做 次乘法。透過分塊重用輸入矩陣元素,主記憶體載入量為 ;不計結果寫回時,可用載入約 個字估算:
因此矩陣矩陣乘法的運算強度隨 線性增加,而非二次增加。
兩台機器的運算上限與記憶體上限如下:
| 機器 | 乘法運算上限 | 記憶體頻寬 |
|---|---|---|
| A | 次乘法/週期 | 字/週期 |
A byte-addressable computer system has a 13-bit logical address, a total physical memory size of 4 KiB, and a page size of 64 bytes. The system uses a segmented paging architecture where the logical address is divided into a Segment Number and a Segment Offset. The segment table provides a Base Address, which is added to the Segment Offset to form a Linear Address. This Linear Address is then translated via a single-level Page Table to a Physical Address.
Logical address: .
Segment Table (Segment Base Address, binary):
- Index 0:
- Index 1:
- Index 2:
- Index 3:
- Index 4:
- Index 5:
- Index 6:
- Index 7:
Page Table (Frame Number, decimal):
- Index 24: 12
- Index 25: 5
- Index 26: 33
- Index 27: 8
第 21 題
What is the Segment Index derived from the logical address ?
(A) 3
(B) 4
(C) 5
(D) 6
登入後即可作答並保存紀錄。
核心觀念
分段分頁架構會先將邏輯位址拆成「段索引」與「段內位移」。段索引用來查段表,段內位移則與段表中的基底位址相加,形成線性位址。
本題段表有 8 個索引,段索引需要 位。邏輯位址共 13 位,因此段內位移占 位。
解題方法
將 寫成 13 位二進位。其完整 16 位表示為 ,取低 13 位:
最左側 3 位是段索引:
第 22 題
What is the Segment Base Address (in hexadecimal) retrieved from the Segment Table?
(A)
(B)
(C)
(D)
登入後即可作答並保存紀錄。
核心觀念
分段架構先將邏輯位址拆成「段號」與「段內位移」。段號用來查詢段表,取出的 Base Address 才會與段內位移相加,形成 Linear Address。本題只問段表查出的 Base Address,因此不需要進行後續的位址相加或頁表轉換。
段表有 8 個索引,需要 3 位元表示段號;邏輯位址共 13 位元,剩下 10 位元是段內位移。
解題方法
將邏輯位址 寫成 13 位元二進位:
由左至右切分為 3 位元段號與 10 位元段內位移:
第 23 題
What is the calculated Linear Address (in hexadecimal)?
(A)
(B)
(C)
(D)
登入後即可作答並保存紀錄。
核心觀念
分段分頁架構會先將邏輯位址拆成「區段編號」與「區段位移」。區段表中的基底位址加上區段位移,得到線性位址:
本題的區段表有 8 個索引,因此區段編號占 位;邏輯位址共 位,剩餘 位為區段位移。
解題方法
將邏輯位址 寫成 13 位元二進位:
前 3 位是區段編號,後 10 位是區段位移:
第 24 題
What is the Virtual Page Number (VPN) index used to look up the Page Table?
(A) 24
(B) 25
(C) 26
(D) 27
登入後即可作答並保存紀錄。
核心觀念
此題考查分段分頁位址轉換。邏輯位址先拆成「段號」與「段內位移」;段表提供的基底位址加上段內位移,形成線性位址。再以線性位址除以頁面大小,取商作為虛擬頁號(VPN),用它查頁表。
頁面大小為 bytes,因此頁內位移占 6 位元,VPN 為線性位址去掉最低 6 位元後的部分。
解題方法
段表有索引 至 ,共 8 個段,因此段號占 位元;13 位元邏輯位址剩下 位元作為段內位移。
將邏輯位址 寫成 13 位元二進位:
取高 3 位元為段號,低 10 位元為段內位移:
查段表索引 5,基底位址為 。因此線性位址為:
第 25 題
What is the final Physical Address (in hexadecimal)?
(A)
(B)
(C)
(D)
登入後即可作答並保存紀錄。
核心觀念
分段分頁架構會依序轉換位址:
- 將邏輯位址切成 Segment Number 與 Segment Offset。
- 查段表,將該段的 Base Address 加上 Segment Offset,得到 Linear Address。
- 依頁面大小,把 Linear Address 切成 Page Number 與 Page Offset。
- 查頁表取得 Frame Number,再將 Frame Number 與 Page Offset 組合成實體位址。
頁面大小為 bytes,因此頁內位移占 6 位元。實體位址的計算式為:
解題方法
邏輯位址 以 13 位元表示為:
段表有 8 個項目,因此 Segment Number 占 3 位元;剩下 10 位元為 Segment Offset:
Consider a file system called TFS that is divided into a series of blocks, each of which is 4 KB. The blocks are indexed from 0 to 31, assuming we have a tiny disk with just 32 blocks. The region of the disk used for user data is the data region, which consists of the last 24 of the 32 blocks on the disk. Additionally, 5 of the 32 blocks are allocated for the inode table, denoted by I’s in the diagram. An inode table is partitioned into multiple i-blocks indexed by i-block (IB) 0 to IB 4. An i-block stores multiple inodes, and the size of each inode is 256 bytes. Finally, the inode bitmap (i), the data bitmap (d), and the superblock (S) each use one 4 KB block.
Disk layout:
- Superblock (S), inode bitmap (i), data bitmap (d), and inode-table blocks occupy disk blocks 0–7; the inode table starts at block 3.
- Inode-table blocks IB0–IB4 occupy disk blocks 3–7. IB0 starts at 12 KB and IB4 ends at 32 KB.
- Data blocks (D) occupy disk blocks 8–31.
第 26 題
What is the maximum number of files that the TFS file system can manage?
(A) 24
(B) 80
(C) 5
(D) 16
🖼️【此處有附圖,見下方】
登入後即可作答並保存紀錄。
核心觀念
inode 表的容量決定檔案系統最多能管理多少個檔案:每個 inode 對應一個檔案,每個 i-block 可存放的 inode 數量為「i-block 大小 ÷ inode 大小」。
解題方法
圖中可讀到 inode table 由 IB0 至 IB4 共 5 個 i-block 組成,每個 block 為 4 KB;題目文字指出每個 inode 為 256 bytes。因此,先計算每個 i-block 可容納的 inode 數,再乘上 i-block 的數量:
第 27 題
The start address of the inode table on the TFS file system is 12 KB. This TFS file system uses five IBs to store the entire inode table. An IB stores multiple inodes, and the inode index starts from 0 in IB0 and is incrementally increased. The last inode is preserved in IB4 with the index 79. Which IB preserves the inode where its index is 16?
(A) 3
(B) 2
(C) 1
(D) 0
登入後即可作答並保存紀錄。
核心觀念
每個 i-block(IB)大小為 bytes,每個 inode 大小為 bytes,因此一個 IB 可存放:
題目從 IB0 開始,inode 索引也從 開始;所以 IB0 存放索引 至 ,IB1 存放索引 至 。
解題方法
將 inode 索引除以每個 IB 可容納的 inode 數量,商即為所屬 IB 編號:
第 28 題
The disk typically consists of a large number of addressable sectors, each of which is 512 bytes in size. To fetch the inode where its index is 16, to which sector of the disk would the file system issue a read?
(A) 32
(B) 16
(C) 8
(D) 4
登入後即可作答並保存紀錄。
核心觀念
磁碟區塊大小為 bytes,每個磁碟扇區大小為 bytes,因此每個區塊包含:
每個 inode 大小為 bytes,所以一個 的 inode-table 區塊可容納:
inode 索引由 開始;因此 inode 0 到 inode 15 位於 IB0,inode 16 起位於 IB1。
解題方法
inode table 從磁碟區塊 3 開始,IB0 對應區塊 3,IB1 對應區塊 4。由於 inode 16 是 IB1 中的第一個 inode,它所在的磁碟區塊編號為 4。
第 29 題
In recent years, general purpose processors have increasingly been supplemented, and in some cases replaced, by specialized accelerators such as GPUs and TPUs. These accelerators depart from traditional CPU designs by prioritizing high throughput computation, data level parallelism, and memory bandwidth over single thread latency and complex control flow. While such designs can deliver orders of magnitude improvements for selected workloads, they also introduce new architectural tradeoffs at the system level. The following question examines the architectural principles that distinguish accelerators from CPUs, and the system-level consequences of these design choices.
Consider a multi-accelerator system executing a workload that performs frequent collective operations (e.g., all-reduce) on large tensors. Which interconnect property is most critical for maximizing sustained throughput?
(A) Minimum single-hop latency
(B) Peak bisection bandwidth
(C) Support for hardware cache coherence
(D) Ability to route packets out of order
登入後即可作答並保存紀錄。
核心觀念
加速器偏重大量資料平行運算;多加速器系統要處理大型張量的集體通訊時,效能常受限於裝置間能搬運多少資料,而非單次訊息的延遲。
**雙分割頻寬(bisection bandwidth)**是將互連網路中的節點分成兩組後,兩組之間所有鏈路可提供的總頻寬。它反映網路在多組裝置同時交換資料時,支援大量並行傳輸的能力。大型張量的 all-reduce 需要在多個加速器間交換大量資料,因此高雙分割頻寬有助於維持整體通訊吞吐量。
解題方法
題目問的是頻繁集體操作、大型張量,以及「持續吞吐量」的最大化。判斷重點是資料交換總量大,且多個加速器會同時通訊。此時應選擇能提高整體跨網路傳輸量的互連特性,即雙分割頻寬。
單跳延遲主要影響單次傳輸開始或完成所需的時間;但當工作負載持續傳送大量資料時,總頻寬更直接限制每秒可傳送的資料量。
選項分析
第 30 題
Compared to a monolithic accelerator with the same aggregate compute resources, a chiplet-based accelerator design necessarily introduces which architectural tradeoff?
(A) Reduced arithmetic throughput per cycle
(B) Increased on-chip memory capacity
(C) Additional communication latency and bandwidth overhead
(D) Lower instruction issue width
登入後即可作答並保存紀錄。
核心觀念
Chiplet 加速器將原本整合在單一晶片上的運算資源,分散到多個小晶粒,再透過晶粒間互連進行資料交換。即使總運算資源相同,跨晶粒通訊仍須經過互連介面與封裝內的連線,因此會帶來額外的通訊延遲與頻寬成本。
解題方法
比較單晶粒與 Chiplet 架構時,重點是找出「拆分成多個晶粒」必然增加的成本。運算資源總量相同,並不代表它們之間的資料傳輸路徑也相同;若資料要跨晶粒傳送,就必須使用晶粒間互連。這些互連的延遲、頻寬限制,以及介面電路的能耗,都是架構上的通訊代價。
選項分析
- (A) 每週期算術運算吞吐量降低:錯誤。
題目已限定總運算資源相同;僅憑採用 Chiplet 架構,不能必然推出每週期算術吞吐量會降低。實際吞吐量仍取決於運算單元設計、排程與資料供應能力。
第 31 題
An accelerator sustains a peak compute throughput of 100 TFLOP/s and a sustained memory bandwidth of 10 TB/s. A kernel has an arithmetic intensity of 4 FLOPs per byte. Which statement is correct?
(A) The kernel is compute-bound at 100 TFLOP/s.
(B) The kernel is memory-bound at 40 TFLOP/s.
(C) The kernel is control-bound due to insufficient parallelism.
(D) The roofline model cannot be applied to this kernel.
登入後即可作答並保存紀錄。
核心觀念
Roofline 模型用運算峰值與記憶體頻寬估算核心的可達效能:
算術強度是每讀寫一個位元組所執行的浮點運算數,單位為 FLOPs/byte。若頻寬限制下的效能低於運算峰值,核心便是記憶體受限。
解題方法
先計算記憶體頻寬所能支援的運算速率:
再與運算峰值 比較:
因此,核心受記憶體頻寬限制,可達效能為 。
選項分析
第 32 題
Given a fixed power and area budget for an accelerator intended primarily for large-model inference, which architectural investment most directly improves end-to-end throughput?
(A) Increasing peak floating-point units per cycle
(B) Increasing instruction window size
(C) Increasing sustained on-chip and inter-chip data bandwidth
(D) Increasing branch prediction accuracy
登入後即可作答並保存紀錄。
核心觀念
大型模型推論的端到端吞吐量,常受資料搬移速度限制。運算單元必須持續取得模型權重與中間資料;若資料供應不足,即使峰值浮點運算能力很高,運算單元也會閒置。
可用 Roofline 模型描述吞吐量上限:
其中,運算強度是每搬移一單位資料所執行的運算量。固定功耗與面積預算下,提高持續的晶片內與晶片間資料頻寬,能讓模型權重和中間結果更快送到運算單元,也能改善多晶片協作時的資料交換效率。
解題方法
先辨認題目設定:加速器以大型模型推論為主,且功耗與面積預算固定。推論需要反覆讀取大量模型權重,並在不同運算單元或晶片間傳遞資料。因此,判斷哪項投資最直接改善端到端吞吐量時,應優先考慮能否持續供應資料、減少運算單元等待的瓶頸。
選項中的浮點運算單元數量提升的是峰值算力;指令視窗與分支預測主要影響一般處理器的指令層級平行性與控制流程。相較之下,提升持續資料頻寬直接改善大型模型推論常見的資料供應瓶頸,故選 C。
選項分析
Consider the following C code and its related 32-bit MIPS assembly code:
C code:
unsigned int fib (unsigned int n) {
if (n < 2) return n;
else return fib(n-1) + fib(n-2);
}
MIPS assembly:
1. fib:
2. addi $sp, $sp, -12
3. sw $ra, 0($sp)
4. sw $s1, 4($sp)
5. sw $a0, 8($sp)
6. slti $t0, $a0, 2
7. beq $t0, $0, L1
8. addi $v0, $a0, 0
9. j EXIT
10. L1:
11. addi $a0, $a0, -1
12. jal fib
13. addi $a1, $v0, 0
14. addi $a0, $a0, -1
15. jal fib
16. add $v0, $v0, $s1
17. EXIT:
18. lw $ra, 0($sp)
19. lw $a0, 8($sp)
20. lw $s1, 4($sp)
21. addi $sp, $sp, 12
22. jr $ra
Register numbers:
- $zero: 0
- $v0–$v1: 2–3
- $a0–$a3: 4–7
- $t0–$t7: 8–15
- $s0–$s7: 16–23
- $t8–$t9: 24–25
- $sp: 29
Opcode/function table:
- 28–26: 0 (000), 1 (001), 2 (010), 3 (011), 4 (100), 5 (101), 6 (110), 7 (111)
- 31–26 = 0 (000): R-format
- 31–26 = 1 (001): Addi
- 31–26 = 2 (010): TLB
- 31–26 = 3 (011): FIPT
- 31–26 = 4 (100): Lb, Lh, Lwl, Lw, Lbu, Lhu, Lwr
- 31–26 = 5 (101): Sb, Sh, Swl, Sw, Swr
- 31–26 = 0 (000), function field 0 (000): Sll; 1 (001): Srl; 2 (010): Sra; 3 (011): Sllv; 4 (100): Srlv; 5 (101): Srav; 6 (110): Jr
- R-format function codes: Add, Addu, Slt, Sltu, Andi, Ori, Xori, Lui
🖼️【此處有附圖,請對照原卷】
第 33 題
Which statement is correct?
(A) If register t0, register utilization can be improved without side-effects.
(B) It is not necessarily necessary to save register ra and $a0 at the start of each function to avoid data loss in situations where a callee subsequently acts as a caller.
(D) One of the reasons why using slti and beq rather than using a single blti (branch less than immediate) instruction is that blti requires two immediate fields that cannot be accommodated within a single 32-bit MIPS instruction format.
登入後即可作答並保存紀錄。
核心觀念
本題考 MIPS 的暫存器呼叫慣例與指令格式。$s 暫存器屬於被呼叫者保存暫存器(callee-saved),函式若改寫它,必須先保存原值並在返回前還原;$a、$t 暫存器則屬於呼叫者保存暫存器(caller-saved),呼叫者若還需要其中的值,必須自行保存。jal 會改寫 $ra,因此遞迴函式若還要返回原呼叫者,必須保留原本的 $ra。
解題方法
依原卷圖可讀到暫存器編號與指令對照表;組合語言第 13 行將 $v0 的值寫入 $s1,第 16 行再使用 $s1 相加。第 2–5 行保存 $ra、$s1、$a0,第 18–21 行則還原並釋放堆疊空間。判斷各選項時,關鍵是確認函式是否改寫該暫存器,以及單一 MIPS 指令能否容納所需欄位。
選項分析
- (A) 錯誤。
$t0是呼叫者保存暫存器,而fib會透過jal fib遞迴呼叫自己;遞迴中的slti也會改寫$t0。若把$s1換成 `
第 34 題
Assume that the execution of each j, jal, beq, and jr instruction takes 3 clock cycles. As invoking the function fib(2), the total number of clock cycles to perform all j, jal, beq, and jr instructions is:
(A) 30
(B) 27
(C) 24
(D) 33
登入後即可作答並保存紀錄。
核心觀念
題目只計算動態執行的 j、jal、beq、jr 指令。每執行一條這四類指令都需 3 個時脈週期,因此:
每次呼叫 fib 都會執行一次 beq 和一次 jr;只有基底情況會執行 j EXIT,每次遞迴呼叫則會執行一次 jal fib。
解題方法
fib(2) 的呼叫關係為:
因此一共呼叫函式 3 次:fib(2)、fib(1)、fib(0)。
第 35 題
The above tables present the register numbers and the corresponding translations of assembly instructions into machine codes. The machine code of the instruction beq 0, L1 (Line 7) is:
(A)
(B)
(C)
(D)
登入後即可作答並保存紀錄。
核心觀念
beq rs, rt, offset 是 MIPS 的條件分支指令,採用 I-format:
分支位移以「下一條指令的位址」為基準,計算公式為:
每條 MIPS 指令長 4 bytes,因此位移單位是指令,而非 byte。
解題方法
Line 7 的指令是 beq $t0, $0, L1。依暫存器編號表,$t0 是 8,$0 是 0,因此:
- opcode:
beq的 opcode 為000100 rs:$t0,編碼為01000rt:$0,編碼為00000
Line 7 的下一條指令是 Line 8;目標 L1 在 Line 10。從 Line 8 前進兩條指令即可到達 Line 10,所以 offset 為 2,16 位元二進位表示是 `0000 0000 0