113 年 國立陽明交通大學資訊工程學系碩士班《計算機系統》
第 1 題4 分
Which of the following x86 instructions cannot be executed in Ring 3 privilege level?
(A) MOV CR0, EAX.
(B) HLT.
(C) LGDT.
(D) LIDT.
登入後即可作答並保存紀錄。
核心觀念
x86 保護模式以目前特權層級(CPL)限制特定指令。CPL 由 0 到 3,數字越小,特權越高;Ring 3 是最低特權的使用者模式。需要管理處理器狀態或控制系統執行的指令屬於特權指令,通常只能在 Ring 0 執行。在 Ring 3 執行這類指令會觸發一般保護例外(#GP)。
解題方法
逐一判斷各指令是否會直接變更處理器控制狀態,或執行僅供核心使用的操作。若指令要求 CPL 為 0,便不能在 Ring 3 執行。
選項分析
- (A)
MOV CR0, EAX:正確。 此指令將 EAX 的值寫入控制暫存器 CR0,會改變處理器的控制狀態,因此是特權操作,須在 Ring 0 執行。 - **(B)
HLT:正確。
第 2 題4 分
Which of the following x86 instructions are position-independent (i.e., the code can be executed at any memory address)?
(A) MOV EAX, 1.
(B) XOR EBX, EBX.
(C) INT 0x80.
(D) ADD EAX, 1.
登入後即可作答並保存紀錄。
核心觀念
位置獨立(position-independent)是指程式碼搬到不同的記憶體位址後,指令仍能正確執行。判斷一條指令是否具位置獨立性,重點在於它是否依賴固定的記憶體位址,例如直接存取某個絕對位址,或跳轉至寫死的位址。
指令若只操作暫存器、使用立即數,或觸發指定的中斷向量,而沒有引用固定的程式碼或資料位址,通常可在不同位置執行。
解題方法
逐一檢查各指令的運算元與作用:
- 暫存器運算不依賴程式所在的記憶體位址。
- 立即數是指令中直接編碼的常數,不代表某個記憶體位置。
- 中斷向量號是指定要觸發的中斷服務,不是程式碼所在位置。
因此,只要指令沒有使用固定記憶體位址或固定跳轉目標,就不會因程式搬移而失效。
選項分析
第 3 題4 分
Consider the following C program on x86_64 Linux.
01 #include <stdio.h>
02 #include <stdlib.h>
03 #include <sys/mman.h>
04 #include <unistd.h>
05
06 int main() {
07
08 size_t pagesize = sysconf(_SC_PAGESIZE);
09
10 void *buffer = aligned_alloc(pagesize, pagesize);
11 if (!buffer) {
12 perror("Failed to allocate memory");
13 return EXIT_FAILURE;
14 }
15
16
17 if (mprotect(buffer, pagesize, PROT_READ | PROT_WRITE | PROT_EXEC) == -1) {
18 perror("mprotect - error 1");
19 free(buffer);
20 return EXIT_FAILURE;
21 }
22
23 sprintf((char *)buffer, "This is a test.\n");
24
25 if (mprotect(buffer, pagesize, 0) == -1) {
26 perror("mprotect - error 2");
27 free(buffer);
28 return EXIT_FAILURE;
29 }
30
31 printf("%s", (char *)buffer);
32 free(buffer);
33
34 return EXIT_SUCCESS;
35 }
Which of the following statement(s) are true?
(A) The program will output “This is a test.” on the screen.
(B) The memory block pointed to by buffer will be allocated on the stack.
(C) The variable pagesize will be allocated on the stack.
(D) After a successful memory allocation, the value of the buffer pointer will be a multiple of pagesize.
登入後即可作答並保存紀錄。
核心觀念
本題考查 C 程式的記憶體配置、aligned_alloc 的對齊保證,以及 Linux mprotect 如何改變記憶頁面的存取權限。
- 區域變數具有自動儲存期;在一般 x86_64 Linux 執行環境中,未被最佳化掉的區域變數通常配置於堆疊。
aligned_alloc(alignment, size)成功時,回傳的位址會符合alignment指定的對齊要求;此外,size必須是alignment的整數倍。mprotect(addr, len, prot)會設定指定記憶頁面的權限。prot為0時代表PROT_NONE,該區域不能讀取、寫入或執行。
解題方法
令系統頁面大小為 。程式以 aligned_alloc(P, P) 配置一個大小為 的區塊。由於配置大小是對齊值的整數倍,且成功回傳的位址符合 的對齊要求,因此 buffer 的位址是 的倍數。
接著,程式先將該頁面設為可讀、可寫、可執行,並用 sprintf 將字串寫入其中。之後執行:
mprotect(buffer, pagesize, 0)
第 4 題4 分
Which statement(s) best describes the Earliest Deadline First (EDF) scheduling algorithm?
(A) EDF prioritizes tasks based on their computational complexity, scheduling the most complex tasks first.
(B) EDF is a preemptive scheduling algorithm that prioritizes tasks based on their proximity to a fixed deadline.
(C) EDF assigns priority to tasks based on the order of their arrival, with the earliest arrivals being processed first.
(D) EDF is a non-preemptive scheduling algorithm that schedules tasks in a round-robin fashion, regardless of their deadlines.
登入後即可作答並保存紀錄。
核心觀念
最早截止期限優先(Earliest Deadline First,EDF)是即時系統中的動態優先權排程法。排程器比較待執行工作的截止時間,優先執行截止時間最早的工作;新工作到達或工作完成時,優先順序可能改變。
EDF 通常採用可搶先方式:若有新工作到達,且其截止時間早於目前執行工作的截止時間,排程器可暫停目前工作,改執行新工作。
解題方法
判斷選項時,抓住 EDF 的兩個特徵:優先權依據是截止時間,而且優先執行截止時間最早的工作。再檢查各選項是否把依據誤說成複雜度、到達順序,或是否否定可搶先排程。
選項分析
第 5 題4 分
On x86_64 systems, Linux system calls are made using the syscall instruction with the following calling conventions:
- RAX contains the system call number.
- RDI, RSI, RDX, R10, R8, and R9 are used to pass up to six arguments to the system call.
- RCX and R11 are clobbered after the syscall instruction.
- The return value of the system call is placed in the RAX register.
The implementation of the sys_write (write) system call in the Linux kernel is as follows.
SYSCALL_DEFINE3(write, unsigned int, fd, const char __user *, buf, size_t, count)
{
return ksys_write(fd, buf, count);
}
The man pages description for sys_write is as follows.
write(2) — System Calls Manual — write(2)
NAME
write — write to a file descriptor
LIBRARY
Standard C library (libc, -lc)
SYNOPSIS
#include <unistd.h>
ssize_t write(int fd, const void buf[.count], size_t count);
DESCRIPTION
write() writes up to count bytes from the buffer starting at buf to the file referred to by the file descriptor fd.
The number of bytes written may be less than count if, for example, there is insufficient space on the underlying physical medium, or the RLIMIT_FSIZE resource limit is encountered (see setrlimit(2)), or the call was interrupted by a signal handler after having written less than count bytes. (See also pipe(7).)
Which of the following statement(s) is true for invoking the sys_write system call?
(A) Need to assign fd to RAX.
(B) Need to assign the address value of buf to RSI.
(C) The actual number of bytes written may be less than the number specified by count.
(D) User-level programs can use syscall to call any function in the kernel.
登入後即可作答並保存紀錄。
核心觀念
x86-64 Linux 使用 syscall 指令進入核心執行系統呼叫。依照題目給定的呼叫慣例:
| 暫存器 | 用途 |
|---|---|
RAX | 系統呼叫編號 |
RDI、RSI、RDX、R10、R8、R9 | 依序傳遞最多六個系統呼叫參數 |
RAX | 系統呼叫完成後存放回傳值 |
write(fd, buf, count) 有三個參數:檔案描述符 fd、緩衝區位址 buf、要寫入的位元組數 count。核心中的 sys_write 再將這些參數傳給 ksys_write。
解題方法
先依序對照 write 的參數與系統呼叫的參數暫存器:
- 第 1 個參數
fd放在RDI。 - 第 2 個參數
buf的位址放在RSI。 - 第 3 個參數
count放在RDX。 RAX放的是write的系統呼叫編號,不是檔案描述符。
第 6 題4 分
Which of the following statements on process are true?
(A) In UNIX, a new process is created by the fork() system call. The new process consists of a copy of the address space of the original process.
(B) A thread shares with other threads belonging to the same process its code section, data section, stack, and other operating-system resources, such as open files and signals.
(C) By using the standard C library, a user program can easily read or write a file from storage devices without the help of operating systems.
(D) When a context switch occurs, the kernel saves the context of the old process in its PCB and loads the saved context of the new process scheduled to run. The context includes the value of the CPU registers, the process state, and memory-management information.
登入後即可作答並保存紀錄。
核心觀念
本題考查行程(process)、執行緒(thread)、系統呼叫,以及行程切換時核心保存的內容。
fork()會建立新的行程。新行程取得原行程位址空間的邏輯副本;現代作業系統常以寫入時複製(copy-on-write)延後實際複製記憶體。- 同一行程中的執行緒共用程式碼、資料及作業系統資源,但每個執行緒有自己的堆疊與暫存器狀態。
- 標準 C 函式庫提供檔案操作介面,但實際存取儲存裝置仍須透過作業系統。
- 行程切換時,核心依據 PCB(Process Control Block,行程控制區塊)保存與還原行程執行所需的資訊。
解題方法
逐項檢查敘述是否符合上述定義。判斷執行緒選項時,特別確認堆疊是否共用;判斷檔案操作時,區分 C 函式庫介面與作業系統提供的實際裝置存取服務。
選項分析
第 7 題4 分
Which of the following statements on I/O system are true?
(A) NAND-flash-based SSDs suffer from limited lifetime. The SSD controller runs a software layer to alleviate this issue by leveling writes without the help from the operating system.
(B) When the CPU detects that a controller has asserted a signal on the interrupt-request line, the CPU performs a state save and jumps to the interrupt-handler routine at a fixed address in memory.
(C) When DRAM generates an interrupt, the CPU saves the state of the user code, switches to kernel mode, and dispatches to the kernel routine or thread that implements the requested service.
(D) In Linux, the swap space is now used only for anonymous memory. That is, Linux will not swap out storage-backed files.
登入後即可作答並保存紀錄。
核心觀念
本題考查三個 I/O 與記憶體管理觀念:
- SSD 耐用度與耗損平均(wear leveling):NAND Flash 的儲存單元可承受的擦寫次數有限,控制器會安排資料寫入位置,避免少數區塊過度磨損。
- 中斷處理流程:CPU 偵測到中斷請求後,保存目前執行狀態,並轉移到中斷處理常式;處理常式的入口可由固定位置或中斷向量取得。
- Linux 的交換空間:交換空間主要用來存放匿名記憶體頁面。檔案支援的頁面若需回收,可直接丟棄,之後再從檔案讀回,不必寫入交換空間。
解題方法
逐項檢查敘述中的機制是否正確:SSD 的寫入管理是否需要作業系統介入、中斷的來源與 CPU 處理步驟是否合理,以及 Linux 會把哪些記憶體頁面寫入 swap。
選項分析
(A) 正確。 NAND Flash 的區塊有有限的擦寫壽命;若反覆寫入集中在少數區塊,這些區塊會較早耗損。SSD 控制器會透過耗損平均,將寫入分散到不同區塊,延長整體使用壽命。這項管理由 SSD 控制器的韌體負責,不需要作業系統協助。
第 8 題4 分
Which of the following statements on memory management are true?
(A) When a CPU needs to access data in DRAM, the DRAM controller verifies the existence of the data. If the data is not found in the main memory, the DRAM controller generates a page fault.
(B) In a system adopting paging, when a process is to be executed, its pages are loaded into any available memory frames from their source (a file system or the backing store).
(C) In Linux and Solaris, the slab-allocation algorithm uses caches to store kernel objects. When a new object for a kernel data structure is needed, the allocator can assign any free object from the cache to satisfy the request.
(D) On Linux, which adopts paging, multiple processes can share one page table to save memory consumption.
登入後即可作答並保存紀錄。
核心觀念
本題考查分頁式記憶體管理、缺頁例外,以及核心物件配置器(slab allocator)。
在分頁系統中,虛擬位址由頁號與頁內位移組成;頁表負責將虛擬頁對應到實體記憶體中的頁框。若要存取的頁不在主記憶體,會由記憶體管理機制觸發缺頁例外,再由作業系統載入所需頁面。slab allocator 則為特定類型的核心物件建立快取,以便快速配置與回收物件。
解題方法
逐一辨認各選項把哪個工作交給哪個元件:DRAM 控制器負責 DRAM 存取;頁表與作業系統負責虛擬記憶體轉譯及缺頁處理;slab allocator 負責配置核心物件。再檢查選項是否正確描述了分頁系統的頁框配置,以及行程間頁表的關係。
選項分析
(A) 錯誤。 DRAM 控制器負責對 DRAM 發出讀寫操作,不會判斷某個虛擬頁是否已載入主記憶體,也不會產生缺頁例外。位址轉譯由記憶體管理單元(MMU)依頁表進行;若頁表顯示頁面不在主記憶體,則由處理器引發例外,交由作業系統處理。
第 9 題4 分
Which of the following statements on virtual memory management are true?
(A) After enabling virtual memory, CPUs operating in user mode can decide to access either physical or virtual addresses based on the compiler configurations.
(B) If a required data is not in physical memory, the user process raises a page fault and runs the page fault handler to transfer the data from storage to memory, possibly relying on DMA for efficiency.
(C) When a process forks a child by using Copy-on-Write (COW), the process and its child share all memory pages until one of them writes to the page.
(D) When a logical address is generated by an x86 CPU, the MMU first checks if its page number is present in the TLB. If not, the CPU walks the page table to get the physical address without the help from the operating system.
登入後即可作答並保存紀錄。
核心觀念
虛擬記憶體將程式使用的位址映射到實體記憶體。使用者程式產生虛擬位址後,記憶體管理單元(MMU)透過轉譯後備緩衝器(TLB)或頁表取得對應的實體位址。若目標頁不在主記憶體,會發生缺頁例外,由作業系統處理。
解題方法
逐項檢查各敘述是否符合虛擬位址轉譯、缺頁處理、寫入時複製(COW)及硬體頁表走訪的工作方式。
選項分析
- (A) 錯誤。 啟用虛擬記憶體後,使用者模式下的程式以虛擬位址存取記憶體,MMU 負責轉譯成實體位址。編譯器設定不會讓 CPU 在實體位址與虛擬位址之間任意選擇。
- (B) 錯誤。 存取不在實體記憶體中的頁面時,CPU 會觸發缺頁例外,轉入核心模式,由作業系統的缺頁處理常式載入資料。
第 10 題4 分
Which of the following statements on file system are true?
(A) A file control block (FCB), an inode in UNIX file systems, contains information about the file, including ownership, permissions, and location of the file contents.
(B) File-name extensions (e.g., .txt, .jpeg) on UNIX systems are necessary and critical, as they guide the operating system to run the right application (e.g., text editor or gallery) for opening files.
(C) Multiple processes may be allowed to map the same file concurrently and to allow sharing of data. Writes by any of the processes modify the data in virtual memory and can be seen by all others that map the same section of the file.
(D) A disk can be sliced into multiple partitions and each partition is not functional without containing a file system. That is, each partition must contain one file system (e.g., NTFS, Ext4).
登入後即可作答並保存紀錄。
核心觀念
檔案系統會記錄檔案的中繼資料與資料位置;行程也能透過記憶體映射存取檔案。判斷時要分清楚「檔案系統必須保存的資訊」、「作業系統是否依副檔名選程式」,以及「共享映射與私有映射」的差別。
解題方法
逐項檢查敘述是否符合檔案系統與記憶體映射的基本定義。特別是共享檔案映射,必須看出選項描述的是共享映射:多個行程對同一檔案區段建立共享映射時,對該區段的修改能由其他映射者觀察到。
選項分析
- (A) 正確。 檔案控制區塊(FCB)或 UNIX 的 inode 會記錄檔案的中繼資料,例如擁有者、權限,以及檔案內容所在的磁碟區塊資訊。檔名通常由目錄項目記錄,不是 inode 本身的主要內容;這不影響選項所列的資訊正確。
第 11 題4 分
For the 32-bit MIPS ISA, an instruction is coded in 32-bit. Different addressing modes are defined in the ISA for instruction and data accessing. Which of the following statements about the MIPS instruction design are true?
(A) The immediate addressing mode and the base addressing mode both use the I-type instruction format, while the PC-relative addressing mode does not.
(B) There are 5 addressing modes in the MIPS ISA.
(C) The immediate values in the pseudodirect addressing mode use word addresses.
(D) A 32-bit constant that has non-zero upper and lower 16-bit halves cannot be loaded into a register using only one instruction (excluding pseudoinstructions).
登入後即可作答並保存紀錄。
核心觀念
MIPS 的定址方式描述指令如何取得運算元或目標位址。常見的五種定址方式為:
- 暫存器定址:運算元位於暫存器。
- 立即定址:運算元直接放在指令的立即數欄位。
- 基底定址:有效位址由基底暫存器加上位移量計算。
- PC 相對定址:分支目標由 加上位移量計算。
- 偽直接定址:跳躍目標由 PC 的高位元與指令中的目標欄位組合而成。
MIPS 的 I 型指令格式包含 16 位元立即數欄位,立即定址、基底定址與 PC 相對定址都會使用 I 型格式。偽直接定址則使用 J 型格式。
解題方法
逐一核對各選項中的定址方式、指令格式與立即數限制。對於 D,檢查 16 位元立即數經符號延伸後,能否產生上下半部皆非零的 32 位元常數。
選項分析
(A) 錯誤。 立即定址與基底定址使用 I 型格式,但 PC 相對定址的分支指令(如 beq、bne)也使用 I 型格式。其分支目標位址為
因此「PC-relative addressing mode does not」不正確。
第 12 題4 分
The following in-order pipelined five-stage MIPS processor design shown in Fig. 1 has a bug.
🖼️【此處有附圖,見下方】
Note that the processor has no forwarding paths, and if it detects data hazards at the decode stage (the hazard control unit is not shown), the pipeline stages will stall properly. If we use the buggy processor to execute the following code segment:
add 1, 0, 1
addi 2, 3
add 4, 1, 0
Assume that initially the registers 4 contain the values 0 through 4, respectively; that is, register 1 is 1, and so on. Which of the following statements are true right after the writeback stage of the fourth instruction (add 4, $3) is complete?
(A) Register 1 has a value of 7.
(C) Register 4 has a value of 4.
登入後即可作答並保存紀錄。
核心觀念
五階段 MIPS 管線必須讓寫回資料與「同一條指令」的目的暫存器編號一起通過管線,才能在 WB 階段寫入正確位置。圖中的錯誤使寫回資料與下一條指令的目的暫存器編號配對。
解題方法
圖中是五階段管線,且沒有 forwarding;題目說明偵測到資料相依時會停等。依圖中的錯誤,逐條追蹤寫回時的資料與目的暫存器:第 條指令的結果會寫到第 條指令的目的暫存器。
初始時 。逐條計算如下:
| 指令 | 計算結果 | 錯誤配對的寫回目的暫存器 |
|---|---|---|
add $4, $1, $2 | 下一條指令的目的暫存器 | |
or $0, $1, $1 | 下一條指令的目的暫存器 | |
addi $2, $2, 3 | 下一條指令的目的暫存器 |
第 13 題4 分
Assume that we have a classical five-stage pipelined 32-bit MIPS processor with a branch predictor and all required forwarding mechanisms. Which of the following statements are true?
(A) If a load instruction is immediately followed by a conditional branch that is dependent on the load result, and we assume that the branch condition is evaluated on the decode stage, one stall cycle is needed to execute the two instructions properly.
(B) The 16-bit immediate value in a branch instruction is imm, and the branch target address is computed by . Here, means sign extension of the parameter imm to 32-bit.
(C) For better performance, the branch target buffer that stores the destination PC for a branch is usually implemented as a tagged memory.
(D) A branch predictor using the information of both a local branch instruction and the global behavior of recently executed branches is called a correlating predictor.
登入後即可作答並保存紀錄。
核心觀念
本題考查五級 MIPS 管線中的資料相依與分支停滯、分支目標位址計算,以及 BTB 與相關式分支預測器的設計。
MIPS 分支指令的 16 位元立即值代表以「指令字」為單位的位移,因此目標位址為:
解題方法
逐一檢查選項的關鍵定義與管線時序。對於資料相依,追蹤資料何時產生,以及分支指令在哪個階段需要該資料;對於位址計算,確認立即值是否還要轉成位元組位移。
選項分析
- (A) 錯誤。 載入指令的資料要到記憶體存取階段末端才取得;若緊接的條件分支在解碼階段比較暫存器,分支需要在解碼階段取得載入結果。標準五級管線的轉送通常供後續執行階段使用,無法讓解碼階段及時取得這筆載入資料,因此需停滯兩個週期,並非一個週期。
第 14 題4 分
Assume that we have two processors, P1 and P2, that are different microarchitecture implementations of the same ISA. The instructions can be divided into four classes according to their CPI (classes A, B, C, and D). P1 has a clock cycle of 1 ns and CPIs of 1, 4, 2, and 3, respectively, for each instruction class. P2 has a clock cycle of 0.8 ns and CPIs of 2, 2, 2, and 2, respectively, for each instruction class.
Given a program with its instructions divided into the four classes as follows: 30% class A, 25% class B, 20% class C, and 25% class D. Which of the following statements about the execution of this program using processor P1 and P2 are true?
(A) The average CPI of P1 is larger than that of P2.
(B) The execution time of P1 is larger than that of P2.
(C) If both processors run at the same clock rate, their CPIs do not change.
(D) For the processor that has longer execution time, it is possible to improve only one of its instruction classes so that it becomes faster.
登入後即可作答並保存紀錄。
核心觀念
平均 CPI 是各指令類別 CPI 依指令比例加權後的平均值:
程式執行時間則為:
因此,比較執行時間時,不能只看平均 CPI;還要乘上時脈週期。
解題方法
先用題目給的指令比例計算兩處理器的平均 CPI:
設程式共有 條指令。P1 的時脈週期為 ns,P2 為 ns,因此:
所以這組設定下,P1 執行時間較長。
選項分析
第 15 題4 分
Which of the following statements about the MIPS ISA design are true?
(A) Not all instructions using the I-type format perform sign-extension on the 16-bit immediate values.
(B) The jump instruction, j, can always jump from address A to address B as long as the offset between A and B is less than words.
(C) MIPS branch instructions are encoded using the I-type format that contains only two registers. This design is based on the principle of making the common case fast.
(D) If we add more R-type instructions to the ISA, and allow the compiler to make use of these extra instructions to compile a program, then the program size in terms of the number of instructions will always be smaller than or equal to the size compiled using the original ISA.
登入後即可作答並保存紀錄。
核心觀念
本題考查 MIPS 的 I-type 與 J-type 指令格式、立即數延伸方式、分支與跳躍的位址計算,以及增加指令集是否必然減少程式的指令數。
MIPS 的 I-type 格式包含 16 位元立即數。立即數的延伸方式依指令種類而定:算術與位址計算常用符號延伸,部分邏輯指令則使用零延伸。分支指令以相對位移計算目標位址;j 指令則將指令中的 26 位元欄位和 PC+4 的高位元組合成目標位址。
解題方法
逐項檢查立即數處理規則、分支與跳躍的位址範圍,再判斷新增指令是否能保證所有程式的指令數都不增加。題目中的「總是」表示必須對所有情況成立,因此只要新增指令本身無法保證指令數下降或維持,就不能成立。
選項分析
(A) 正確。
I-type 指令的 16 位元立即數並非一律符號延伸。例如 addi、lw、sw 等指令會將立即數符號延伸;andi、ori、xori 則將立即數零延伸。lui 也有特殊處理方式,將立即數放入結果的高 16 位元。因此「並非所有 I-type 指令都對立即數做符號延伸」正確。
(B) 錯誤。
j 指令的目標位址由 PC+4 的高 4 位元,以及指令中的 26 位元位址欄位組成;低 2 位元補零:
第 16 題4 分
Which of the following statements are true?
(A) AI accelerator chips require access to extensive data during their operation. Therefore, enhancing memory access and mitigating the impact of large memory requirements pose significant challenges in the design of AI accelerators.
(B) Conducting Large Language Model (LLM) inference at the edge of computing provides a direct enhancement to information security.
(C) High-performance GPUs are crucial for developing LLMs. Consequently, power optimization is no longer a concern in GPU design.
(D) The increase of a CPU’s clock rate is constrained by CPU’s power consumption, while a GPU, with its distinct architecture, avoids the limitation of clock rate imposed by power consumption.
登入後即可作答並保存紀錄。
核心觀念
本題考查 AI 加速器的記憶體需求、邊緣推論的資料安全效益,以及處理器效能與功耗之間的關係。
AI 模型執行時,除了需要大量運算,也需要頻繁讀取權重、輸入資料與中間結果。因此,記憶體頻寬、容量及資料搬移成本都是加速器設計的重要考量。另一方面,處理器的功耗與散熱會限制可達時脈;GPU 的平行架構不會使這項限制消失。
解題方法
逐項檢查敘述是否符合上述硬體原理。判斷時特別留意「直接提升安全性」與「不再受功耗限制」這類概括說法:前者要看資料是否減少離開裝置,後者則要確認架構是否真的能免除功耗限制。
選項分析
(A) 正確。 AI 加速器執行時需要存取大量模型權重、輸入資料及中間運算結果。若資料無法及時由記憶體供應,運算單元便會等待,降低整體利用率。因此,提高記憶體存取效率、降低資料搬移成本,並處理龐大的記憶體需求,都是 AI 加速器設計的重要挑戰。
第 17 題4 分
Consider the CPU performance and the instruction count at the machine level, which of the following statements are true?
(A) When comparing two algorithms designed to solve the same problem, the one with higher complexity typically demands a greater number of instructions to complete the operation compared to the other.
(B) As we implement the same algorithm in Python and C programming languages, the Python program generally requires a greater number of instructions than the C program to execute the algorithm.
(C) The Millions of Instructions Per Second (MIPS) performance metric may not be equitable, as an instruction set with lower CPI can achieve a higher clock rate but necessitates a larger number of instructions.
(D) Google’s warehouse-scale computer centers typically maintain server utilization levels ranging from 70% to 90%, ensuring the optimal utilization of server resources.
登入後即可作答並保存紀錄。
核心觀念
CPU 執行時間可表示為:
因此,效能不只受時脈頻率影響,也取決於完成工作所需的指令數量與平均每指令週期數(CPI)。分析選項時,要分清演算法的運算量、程式語言產生的機器指令數,以及 MIPS 指標的限制。
解題方法
逐項判斷各敘述是否符合上述關係。A、B 比較完成相同工作的指令數量;C 檢視 MIPS 是否能公平比較不同指令集或處理器;D 則判斷高伺服器使用率是否必然代表資源運用最佳。
選項分析
(A) 正確。
對同一問題而言,時間複雜度較高的演算法,在輸入規模增加時通常需要更多基本運算,因此通常也會執行更多機器指令。例如,輸入大小為 時, 演算法的運算量通常會比 演算法成長得快。實際指令數仍會受實作與編譯方式影響,但題目以「typically」描述一般情況,敘述成立。
第 18 題4 分
Which of the following statements are correct?
Fig. 2:
🖼️【此處有附圖,見下方】
Fig. 3:
🖼️【此處有附圖,見下方】
Fig. 4:
🖼️【此處有附圖,見下方】
(A) Fig. 2 shows a correct 3-bit × 3-bit multiplier.
(B) Fig. 3 shows a wrong 32-bit × 32-bit multiplier.
(C) The most significant bit of a carry look-ahead adder often experiences elevated input loading, leading to increased delays. Employing a multi-level carry look-ahead adder helps mitigate the issue of high input loading.
(D) Consider the 16-bit two-level carry look-ahead adder in Fig. 4 and the timing of transitioning to correct values on each signal line. transitions to the correct value before , and transition to correct values prior to , for to , and transitions to the correct value prior to to , for to .
登入後即可作答並保存紀錄。
核心觀念
本題考兩個重點:乘法器的部分積位移與進位保留,以及階層式超前進位加法器(CLA)的訊號相依關係。
對無號 位元乘法而言,若被乘數為 ,乘數各位元為 ,則
三個部分積必須依位元權重對齊,而且加法產生的進位不能遺失。完整乘積最多需要 位元。
CLA 則利用每一位的進位產生與傳遞訊號:
其中乘法表示邏輯 AND, 表示邏輯 OR。
解題方法
原卷可見的 Fig. 2 有兩個串接的 位元 ALU,輸入為三組部分積,中間輸出標示為 位元,並分接至乘積輸出與下一層;圖中未畫出額外的進位保存路徑。附上的兩頁沒有 Fig. 3、Fig. 4,因此無法核對(B)的具體錯接位置及(D)的實際閘級延遲;這兩項依學校公布判定列為正確,並以標準階層式 CLA 說明相關原理。
乘法器的檢查方法是追蹤位元權重與進位;CLA 的檢查方法則是追蹤位元訊號 → 群組訊號 → 群組進位 → 群組內進位的相依順序。
選項分析
(A)錯誤:Fig. 2 的中間結果未完整保留進位。
部分積累加時,即使兩個輸入都只有 位元,相加結果仍可能需要 位元。圖中的 位元輸出若沒有另行保存進位,就會丟失乘積的高位資訊。
例如取
依逐位累加部分積的方式,先保留最低位乘積,再把其餘位元移至下一個權重。第一層須處理的加法為
此結果需要 位元;若只留下 位元,就會遺失最高位的進位。正確乘積應為
因此,不能只看「有三組部分積、兩個 ALU」就認定乘法器正確;Fig. 2 所示的進位處理不足,(A)不成立。
(B)正確,依學校公布判定。
第 19 題4 分
Which of the following statements about computer arithmetic are correct?
🖼️【此處有附圖,見下方】
(A) The hardware depicted in Fig. 5 serves dual functions, functioning as both a multiplier and a divider. The Product/Remainder register necessitates a shift-right operation for multiplication and a shift-left operation for division. The control test unit receives its input from P2 when operating as a multiplier and from P1 when operating as a divider.
(B) For floating-point addition, aligning decimal points involves shifting the number with the smaller exponent to ensure proper alignment. This is because rounding the significand of the number with smaller exponent has a minor impact on accuracy. Conversely, if decimal points are aligned by shifting the number with the larger exponent, it may result in overflow on the significand of the number with the larger exponent.
(C) Addition is associative for both integers and floating-point numbers.
(D) Assuming the accuracy of a floating number is to the second decimal place and rounding half down with additional guard, round, and sticky bits, the ULP of the addition is .
Note: .
登入後即可作答並保存紀錄。
核心觀念
本題考查乘法器的部分乘積位權,以及進位前瞻加法器(CLA)的邏輯結構與延遲。判斷時須區分:
- 扇入(fan-in):同一邏輯閘接收多少個輸入。
- 扇出(fan-out)與負載:一個訊號需要驅動多少個後續輸入。
- 階層式進位計算:先產生各組的傳播、生成訊號,再求組間進位,最後求組內進位。
解題方法
原卷頁圖印刷的四個選項,實際討論的是 Fig. 2 的 位元乘法器、Fig. 3 的 位元乘法器,以及 Fig. 4 的兩層 CLA;與文字題幹所列的 Fig. 5、浮點運算選項不同,因此以下依原卷印刷內容解說。附圖包含 Fig. 3、Fig. 4,但缺少判讀選項(A)所需的 Fig. 2。
Fig. 3 將部分乘積送入標示為 32 位元的加法樹,並在左側直接引出高位乘積。Fig. 4 則由四個 4 位元 CLA 與一個第二層 CLA 組成:各組產生群組生成訊號 、群組傳播訊號 ,第二層計算 ,再送回各組。
選項分析
(A)不列入答案;附圖缺少必要的 Fig. 2。
原卷選項為「Fig. 2 顯示正確的 位元乘法器」。
驗證這項敘述,必須查看 Fig. 2 的部分乘積位移、加法器接線,以及進位是否接到正確的位權。這些資訊未出現在附上的頁圖中,因此不能提出該電路的具體錯誤,也不能以缺圖本身判定電路錯誤。學校公布答案為 BD,故(A)不列入正確選項;其電路上的錯誤位置須配合 Fig. 2 才能說明。
(B)正確:Fig. 3 的乘法器有位權與高位進位處理問題。
令兩個無號 32 位元運算元為 、,則乘積為
每個部分乘積都必須依乘數位元的位置左移。尤其最高部分乘積 ,本身的最高有效位置是第 62 位;第 63 位必須由部分乘積相加時的進位形成。
Fig. 3 卻在最左側部分乘積進入加法器之前,直接分出一條線作為 ,這不符合上述位權關係。
用一組簡單輸入即可驗證:
第 20 題4 分
The (7,4) Hamming code has bit indices ranging from 1 to 7 (left to right). Parity bits , , and are bits 1, 2, and 4, respectively. Data bits are bits 3, 5, 6, and 7. Which of the following statements are true?
(A) The word 1010111 is not correct, and bit 6 should be 0.
(B) Add an additional parity bit for the whole word and make it satisfy ( even). This will increase the Hamming distance to 4.
(C) The word 01000101 is not correct. should be 0.
(D) The word 10010011 is not correct and should have double errors since even holds and .
登入後即可作答並保存紀錄。
核心觀念
漢明碼使用偶同位元。每個同位元檢查一組位元,將該組位元相加後取模 ;檢查結果為 表示該組符合偶同位元,為 表示不符合。
位元索引由左至右為 到 ,三組檢查如下:
若加上整體偶同位元 ,則 是第 8 位,需使前 8 位總和為偶數。三個漢明檢查結果合稱症候,能指出單一錯誤的位置;再配合整體同位元檢查,可以區分單一錯誤與雙重錯誤。
解題方法
逐一依位元索引計算各組同位元。計算同位元時,加法皆在模 下進行,也就是只看總和的奇偶性。加上 的題目,則另外檢查前 7 位的奇偶性,以求出使整體為偶數的 。
選項分析
(A) 正確
字串 的位元依序為 。三組檢查結果為:
不符合的檢查是 、,症候對應位置 。因此第 6 位應翻轉;原本為 ,修正後為 。
(B) 正確
加入 形成延伸漢明碼。原 漢明碼的最小漢明距離為 ;加上整體偶同位元後,所有碼字的重量都為偶數。原本重量為 的碼字會由 補成重量 ,重量為 的碼字則維持重量 ,因此延伸碼的最小距離為 。
(C) 錯誤
位元依序為 。
Consider the following C code snippet:
01 #include <stdio.h>
02 #include <string.h>
03
04 void safeFunction() {
05 printf("This is a safe function call.\n");
06 }
07
08 void vulnerableFunction(char *str) {
09 char buffer[50];
10 strcpy(buffer, str);
11 }
12
13 int main(int argc, char *argv[]) {
14 if (argc > 1) {
15 vulnerableFunction(argv[1]);
16 }
17 return 0;
18 }
Assume that the program runs on x86-64 Linux.
第 21 題
For the command-line argument , which of the following situations would corrupt the stack?
(A) If contains a non-printable character.
(B) If contains a space.
(C) If is a comma-delimited string of the phone numbers of all NYCU CS faculty members.
(D) None of the above.
登入後即可作答並保存紀錄。
核心觀念
buffer 是函式堆疊上的字元陣列,容量為 50 bytes。strcpy(buffer, str) 會從 str 複製字元,直到並包含字串結尾的 \0,但不會檢查目的陣列容量。
因此,若輸入字串長度為 ,strcpy 會寫入 bytes。當 時,寫入內容超過 buffer 的容量,會覆寫相鄰的堆疊資料,造成堆疊破壞;若覆寫到控制資料,還可能影響程式流程。
解題方法
判斷重點是輸入字串的長度是否超過緩衝區容量,而不是字元是否可列印、是否含空白。argv[1] 是命令列參數字串,strcpy 會將它複製到 50 bytes 的 buffer。
長度不超過 49 bytes 時,還能容納結尾的 \0;長度達 50 bytes 以上時,便會超出陣列範圍。
第 22 題
If the stack is corrupted, which of the following is least likely to be affected?
(A) The program control flow.
(B) The local variables.
(C) The function call arguments.
(D) The program code.
登入後即可作答並保存紀錄。
核心觀念
strcpy(buffer, str) 不檢查來源字串長度。若輸入超過 buffer 的容量,資料會越界寫入,破壞堆疊上的資料。堆疊通常存放函式的區域變數、部分函式呼叫資訊,以及返回位址等控制資訊;程式指令則通常存放在程式碼區段,不在堆疊上。
解題方法
判斷各選項是否位於堆疊,或會受堆疊遭破壞的直接影響:
- 區域變數與函式呼叫資訊可能位於堆疊中,會被越界寫入影響。
- 返回位址等控制資訊遭破壞時,程式控制流程可能改變。
- 程式碼本身通常位於獨立的程式碼區段,不會因堆疊資料遭覆寫而直接改變。
選項分析
Assume each page is 512 bytes in size and the size of an integer is 2 bytes. Consider two C programs (Program 1 and Program 2) designed to initialize all elements of a two-dimensional array (called arr below) to 0. The array is stored in row-major order; that is, the array is stored as , , …, , , and so on. If the operating system only allocates 128 page frames on-demand to each program and adopts Least-Recently-Used (LRU) page replacement policy to manage those frames, please answer the following two questions.
Program 1:
int x, y;
int [][] arr;
for (y = 0; y < 256; y++)
for (x = 0; x < 256; x++)
arr[x][y] = 0;
Program 2:
int x, y;
int [][] arr;
for (x = 0; x < 256; x++)
for (y = 0; y < 256; y++)
arr[x][y] = 0;
第 23 題
How many page faults would be generated while running Program 1?
(A) 1
(B) 128
(C) 256
(D) 65536
登入後即可作答並保存紀錄。
核心觀念
本題考查列優先儲存(row-major)下的記憶體存取順序,以及 LRU 頁面置換造成的缺頁。
陣列共有 個整數,每個整數 bytes,因此總大小為
每頁 bytes,所以陣列占用
每頁可存放 個整數,剛好是一整列。程式每寫入一個尚未載入記憶體的頁面,就會產生一次缺頁;每個程式最多只有 個頁框。
解題方法
Program 1 的迴圈順序是 在外、 在內。固定一個 時,內層依序存取:
由於陣列採列優先儲存,這些位置分散在 個不同頁面中:每個 都位於第 列所屬的頁面。內層走完一輪,便依序碰到全部 頁。
第 24 題
How many page faults would be generated while running Program 2?
(A) 1
(B) 128
(C) 256
(D) 65536
登入後即可作答並保存紀錄。
核心觀念
分頁系統以固定大小的頁面管理虛擬記憶體。程式第一次存取尚未載入實體記憶體的頁面時,會發生一次 page fault;之後只要該頁仍在記憶體中,存取同一頁的其他資料就不會再次發生 page fault。
陣列採 row-major 儲存,代表同一列的元素連續排列。本題每個整數占 bytes,因此一列的大小為
恰好等於一個頁面的大小。
解題方法
Program 2 的存取順序如下:
for (x = 0; x < 256; x++)
for (y = 0; y < 256; y++)
arr[x][y] = 0;
固定一個 ,內層迴圈依序存取 到 。這些元素在記憶體中連續排列,剛好占一頁。因此,處理每一列時,第一次存取該列會造成一次 page fault;其餘 次存取都命中同一頁。
共有 列,所以 page fault 總數為
陣列總大小也可用來驗算:
is a single-issue, in-order execution, five-stage pipeline implementation of the MIPS ISA without a branch prediction unit and without any data-forwarding path. The registers are read at the second half cycle of the Decode stage. The registers are written at the first half cycle of the Writeback stage. The branch decisions and targets are determined at the Execute stage. The fetch of the next instruction after a branch will be stalled until the branch decision is made. Answer the following questions when is used to execute Program 3.
Program 3:
addi zero, 8
addi s1, t0, 100(t0, s2
sw s1)
addi s1, -4
bne zero, Loop
addi zero, $zero
第 25 題
How many total stall cycles will be inserted into the pipeline for proper execution throughout the entire program?
(A) 8
(B) 12
(C) 16
(D) 18
登入後即可作答並保存紀錄。
核心觀念
五階段 MIPS 管線為 IF、ID、EX、MEM、WB。題目指定沒有資料轉送,因此讀取來源暫存器的指令必須等到前一指令在 WB 階段寫回後,才能在 ID 階段讀取。由於 WB 在前半個週期寫入、ID 在後半個週期讀取,兩者可在同一週期完成。
因此,若消費指令緊接在產生指令之後,必須插入 2 個資料停滯週期,讓消費指令的 ID 與產生指令的 WB 對齊。
分支在 EX 階段才決定是否跳躍及目標位址;在決定之前,取指器會停等。分支位於 IF 後,後續取指需等待其通過 ID、EX,因此每次分支造成 2 個控制停滯週期。
解題方法
先計算程式動態執行次數,再逐一找出相鄰指令間的 RAW(讀後寫)相依,以及分支停滯。
初值為 ,每次迴圈減 。分支檢查減法後的 ,故迴圈執行兩次:第一次由 減為 ,分支成立;第二次由 減為 ,分支不成立。總共執行兩次分支。
資料停滯如下:
| 相依指令 | 相依暫存器 | 停滯週期 |
|---|---|---|
初始 addi $s1, $zero, 8 → addi $s2, $s1, $zero | $s1 | 2 |
每次迴圈的 lw $t0, 100($s1) → addu $t0, $t0, $s2 | $t0 | 2 |
第 26 題
How many stall cycles are due to control hazards?
(A) 2
(B) 4
(C) 6
(D) 8
登入後即可作答並保存紀錄。
核心觀念
控制冒險發生在分支指令改變程式控制流程時。此處分支在 EX 階段才決定是否跳躍及目標位址,而且下一條指令的取指會一直停住,直到分支結果確定。因此,每次執行分支指令,都要計入分支決策前被停住的取指週期。
解題方法
先算出迴圈執行次數,再計算每次分支造成的控制冒險停滯週期。
初始時 $s1 = 8。每次迴圈都執行 addi $s1, $s1, -4,接著以 bne $s1, $zero, Loop 判斷是否返回:
- 第一次執行迴圈後,
$s1 = 4,分支成立,返回Loop。 - 第二次執行迴圈後,
$s1 = 0,分支不成立,離開迴圈。
所以分支指令共執行 次。由於分支在 EX 階段才決定,每次分支的下一條指令都會在分支的 ID 與 EX 階段各停住一次,合計 $2
第 27 題
How many stall cycles can be removed by adding only the forwarding path from the EX/MEM register to one of the inputs of the ALU in the execute stage?
(A) 6
(B) 8
(C) 10
(D) 12
登入後即可作答並保存紀錄。
核心觀念
沒有資料轉送時,消費指令必須等到生產指令在 WB 階段寫回,才能在 ID 階段讀到新值。暫存器在 WB 前半拍寫入、ID 後半拍讀取,因此消費指令可在生產指令 WB 的同一個週期讀取。
EX/MEM 轉送可把前一條指令的結果送到後續指令的運算元端,縮短相鄰指令間的 RAW 資料相依停滯。題目中的迴圈執行兩次: 依序為 、,再減為 。
解題方法
先找出每一組相依,再比較加入轉送前後可省下的停滯週期:
| 生產指令 → 消費指令 | 執行次數 | 每次可移除的停滯 | 合計 |
|---|---|---|---|
第一條 addi 寫入 $s1 → 第二條 addi 讀取 $s1 | 1 | 2 | 2 |
addu 產生 $t0 → sw 使用 $t0 | 2 | 2 | 4 |
addi $s1, $s1, -4 產生 $s1 → bne 讀取 $s1 | 2 | 2 | 4 |
因此可移除的停滯週期數為
Consider a 16-bit computer with a hierarchical memory system consisting of a disk, a -byte main memory using byte-addressing, and a two-level cache with primary cache of -byte inside CPU. The primary cache is designed as follows: it is a direct-mapped cache. Each block is 16-word long and the replacement policy is LRU. The OS adopts a 16-bit virtual address with a page size of 0.5 KB.
第 28 題
Which configuration of the hierarchical memory system is true?
(A) The hierarchical memory system is suited to apply physically tagged and virtually indexed scheme since the virtual page offset field is equal to or longer than the index field for cache addressing.
(B) The virtual memory has pages.
(C) The virtual page number field has a length of 6 bits.
(D) The tag field of physical address has a length of 8 bits.
登入後即可作答並保存紀錄。
核心觀念
這題考查位址切割,以及虛擬索引、實體標記快取(VIPT)的適用條件。直接對映快取的位址可分成:
虛擬記憶體位址則分成:
解題方法
題目是 16 位元電腦,因此一個 word 為 16 bits,也就是 2 bytes。每個快取區塊有 16 words,大小為:
因此區塊內位移欄位為 5 bits。主快取大小為 bytes,直接對映下的快取行數為:
所以 Index 欄位為 4 bits。主記憶體位址為 16 bits,實體位址切割為:
頁面大小為 KB,即 bytes,所以 Page offset 為 9 bits。16 位元虛擬位址的 VPN 長度為:
第 29 題
Without regarding the disadvantage of virtually addressed cache, the virtually addressed cache is used in this computer. Assume the cache is empty initially. Given the following virtual address accesses to access cache: 0x8A78, 0x8A64, 0x8876, 0x8FF8, 0x8DE7. Which statement is true?
(A) The result of access to 0x8A64 is miss.
(B) The result of access to 0x8876 is hit.
(C) The result of access to 0x8FF8 is miss and the block containing 0x8A78 is replaced.
(D) The result of access to 0x8DE7 is miss and the block containing 0x8FF8 is replaced.
登入後即可作答並保存紀錄。
核心觀念
快取區塊大小為 16 個字,每字 16 位元,也就是 2 位元組,因此每個區塊有 位元組。主快取容量為 位元組,採直接對映,所以共有:
以虛擬位址直接查詢快取時,位址可分成區塊內位移、快取列索引與標籤:
- 區塊內位移: 位元
- 快取列索引: 位元
- 標籤: 位元
解題方法
將每個位址除以區塊大小 ,商為區塊編號、餘數為區塊內位移。區塊編號的低 4 位元決定快取列索引,其餘高位元是標籤。相同索引且標籤相同為命中;索引相同但標籤不同為衝突,會取代該列原有區塊。
| 存取位址 | 區塊編號 | 快取列索引 | 標籤 | 結果 |
|---|---|---|---|---|
| Miss,載入列 3 | ||||
| Hit,與前一位址同區塊 |
第 30 題
If the CPU base CPI = 1 and the CPU clock is running at 5 GHz. The miss rate per lw/sw instruction in primary cache is 2%. There are 25% lw/sw instructions in a program. The access time to the second-level cache is 6 ns and the global miss rate to main memory is 0.2% with the miss penalty of 240 ns. Which statement is true?
(A) If the CPU has only primary cache without the second-level cache, the effective CPI is 6.
(B) If the CPU has only primary cache without the second-level cache, the effective CPI is 7.5.
(C) The CPU with 2-level cache has the effective CPI of 4.9.
(D) The CPU with 2-level cache has the effective CPI of 4.2.
登入後即可作答並保存紀錄。
核心觀念
快取造成的有效 CPI 可用下式計算:
每指令的 L1 miss 次數,需將「每個 lw/sw 指令的 miss rate」乘上 lw/sw 指令占比。時間換算成週期時,使用:
解題方法
時脈為 ,所以一個時脈週期為:
lw/sw 占所有指令的 ,且其 L1 miss rate 為 ,因此每指令平均 L1 miss 次數為:
若採一般兩層快取的停滯時間算法,L1 miss 時先花 存取 L2;L2 未命中的全域 miss rate 為 ,再增加 的主記憶體 miss penalty。平均每次 L1 miss 的停滯時間為:
換算成週期後,兩層快取的有效 CPI 為: