113 年 國立成功大學電機工程學系碩士班已組《計算機組織與作業系統》

📄 試題原卷 免費註冊後即可對照原始考卷 PDF免費註冊

第 1 題10 分

  1. (10pts, no partial point, no penalty) In the context of operating systems, which of the following statements is/are true regarding deadlock prevention and avoidance?
    (a) Deadlock prevention techniques involve designing the system in such a way that deadlocks can never occur.
    (b) Deadlock avoidance techniques dynamically analyze the resource allocation state to ensure that a safe state is maintained.
    (c) Banker's algorithm is an example of a deadlock prevention technique.
    (d) Wait-die and wound-wait are deadlock avoidance strategies used in transaction processing systems.

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

這一題的完整詳解

解說

  • (a) 正確。Deadlock prevention 透過系統設計(例如破壞必要條件)使死結不可能發生。
  • (b) 正確。Deadlock avoidance 依據目前資源配置即時判斷,僅允許使系統保持於 安全 state。
  • (c) 錯誤。
🔒

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

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

免費註冊

第 2 題10 分

  1. (10pts, no partial point, no penalty) Consider advanced concepts in storage management. Which of the following statements is/are true?
    (a) Copy-on-write (COW) is a technique used in file systems to duplicate data for redundancy.
    (b) Snapshotting in storage systems allows for the creation of point-in-time copies of data without consuming additional storage space.
    (c) Tiered storage involves dynamically moving data between different storage tiers based on access patterns and usage.
    (d) Write-back caching and write-through caching are two strategies used in storage systems to manage data consistency.
    (e) Redundant Array of Independent Disks (RAID) primarily focuses on optimizing storage performance without addressing data redundancy.

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

這一題的完整詳解

核心觀念

本題考查現代高階儲存管理(Advanced Storage Management)的核心觀念與技術,包含以下關鍵主題:

  1. 寫入時複製(Copy-on-Write, COW):一種資源共享與延遲複製機制,旨在優化記憶體與儲存系統的效能與空間利用率,而非用於提供資料備份與冗餘(Redundancy)。
  2. 快照(Snapshotting):建立特定時間點(Point-in-Time)的資料視圖。建立瞬間透過指標(Metadata Pointers)指向原資料,無須立即複製實體資料區塊,故建立時不額外消耗實體儲存空間。
  3. 分層儲存(Tiered Storage):根據資料的存取頻率與使用模式(如熱資料與冷資料),自動且動態地將資料遷移至適當的儲存介質層階(如 NVMe SSD、SATA SSD、HDD、雲端儲存)。
  4. 快取寫入策略(Write-through / Write-back Caching):快取層與次級儲存層之間處理寫入資料更新與維護資料一致性/持久性(Data Consistency / Durability)的兩大核心策略。
  5. 獨立磁碟冗餘陣列(RAID):透過結合多實體磁碟提供資料容錯(Fault Tolerance)、資料冗餘(Data Redundancy)與存取效能優化。

解題方法

評估各選項敘述是否符合作業系統與儲存系統理論:

  1. 分析 COW 的設計初衷:區分「資料共享與延遲複製」與「資料備份與冗餘」的差異。
  2. 理解快照的實作原理:快照建立時利用元資料指標記錄狀態,建立當下的空間開銷為 00(或僅需極微量指標空間)。
  3. 確認 Tiered Storage 的定義:檢視其是否為基於存取模式(Access Patterns)的動態資料遷移機制。
  4. 釐清快取寫入策略的功能:直寫(Write-through)與寫回(Write-back)均為控制快取與底層儲存資料一致性與寫入效能的策略。
  5. 檢查 RAID 的定義:由 RAID 名稱中的 "Redundant" 即可判定其核心目標必然包含資料冗餘度。

選項分析

  • (a) 錯誤
    寫入時複製(Copy-on-Write, COW) 是一種優化系統資源開銷的技術(廣泛應用於 fork() 的頁面共享以及 ZFS / Btrfs 等檔案系統)。其原理為:當多個主體共享同份資料時,系統先不進行複製;直到某個主體欲修改資料時,才複製該區塊並進行寫入。其主要目的是避免不必要的實體複製以節省記憶體/儲存空間與時間,而非為了提供資料備份或冗餘性(Redundancy)。

  • (b) 正確
    儲存系統中的 快照(Snapshotting) 指的是擷取特定時間點(Point-in-Time)的資料狀態。

🔒

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

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

免費註冊

第 3 題10 分

  1. (10pts, no partial point, no penalty) In the context of process synchronization, which of the following statements is/are true?
    (a) Semaphore is a synchronization primitive that allows multiple processes to access a shared resource simultaneously.
    (b) The critical section problem involves ensuring that no two processes are in their critical sections at the same time.
    (c) Deadlocks can occur when processes are waiting indefinitely for a condition to become true.
    (d) Peterson's solution is a hardware-based approach to mutual exclusion.
    (e) Message passing is a synchronization technique that involves communication between processes using shared variables.

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

這一題的完整詳解

核心觀念

本題旨在考驗作業系統中「行程同步與互斥」(Process Synchronization & Mutual Exclusion)、「死鎖」(Deadlock)以及「行程間通訊」(Inter-Process Communication, IPC)的基本概念與專有名詞定義。重點涵蓋:

  1. 訊號量(Semaphore):計數訊號量(Counting Semaphore)與二元訊號量(Binary Semaphore)的資源存取控制機制。
  2. 臨界區段問題(Critical Section Problem):三大規範(Mutual Exclusion、Progress、Bounded Waiting)中「互斥(Mutual Exclusion)」的嚴格定義。
  3. 死鎖(Deadlock):行程因等待特定條件或事件發生而陷入無限期等待(Indefinite Waiting)的系統狀態。
  4. 軟體與硬體同步解法:Peterson's Solution(純軟體解法)與原子硬體指令(如 TestAndSet、CompareAndSwap)之分類。
  5. IPC 機制比較:共享記憶體(Shared Memory)與訊息傳遞(Message Passing)的運作模式差異。

解題方法

本題為概念判遞型多重選擇題,切入點為將各選項敘述與作業系統標準權威教材(如 Operating System Concepts by Silberschatz et al.)之定義進行逐項比對:

  1. 精確釐清同步原語的性質(如 Semaphore 允許存取資源的上限數量)。
  2. 分清同步解決方案的實作層級(軟體演算法 vs. 硬體指令)。
  3. 區隔 IPC 兩種主要架構傳遞資料的方式(使用 Shared Variables vs. 透過 OS Kernel 傳送 Messages)。
  4. 逐一判定各選項之真偽並標明錯誤關鍵。

選項分析

  • (a) Semaphore is a synchronization primitive that allows multiple processes to access a shared resource simultaneously.(正確)

    • 分析:訊號量(Semaphore)包含「二元訊號量(Binary Semaphore)」與「計數訊號量(Counting Semaphore)」。計數訊號量的初始值可設定為正整數 NN(代表資源共有 NN 個可用單位)。當多個行程欲存取該共享資源時,只要計數值大於 00,系統可允許最多 NN 個行程「同時/並行(simultaneously / concurrently)」進入並存取該共享資源。因此,本敘述完全符合計數訊號量的定義與功能設計。
  • (b) The critical section problem involves ensuring that no two processes are in their critical sections at the same time.(正確)

    • 分析:臨界區段問題(Critical Section Problem)的核心要求包含三大要件:互斥(Mutual Exclusion)、進展(Progress)、有限等待(Bounded Waiting)。其中「互斥」的官方定義即為:「若行程 PiP_i 正在其臨界區段(Critical Section)內執行,則其他任何行程皆不得同時在其臨界區段內執行。」意即保證任何時間點最多僅能有一個行程處於臨界區段中。
  • **(c) Deadlocks can occur when processes are waiting indefinitely for a condition t

🔒

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

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

免費註冊

第 4 題10 分

  1. (10pts, no partial point, no penalty) Which of the following statement about virtual memory is/are TRUE?
    (a) Demand paging is a technique that brings a page into memory only when it is needed.
    (b) The working set model helps determine the minimum number of frames required to avoid page faults.
    (c) Thrashing occurs when the system spends a significant amount of time swapping pages in and out of memory.
    (d) Page tables are used to map virtual addresses to physical addresses.
    (e) The Belady's anomaly describes a situation where increasing the number of frames in a system leads to an increase in page faults.

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

這一題的完整詳解

核心觀念

本題考驗虛擬記憶體(Virtual Memory)管理機制的五項核心概念:

  1. 請求分頁(Demand Paging):頁面載入記憶體的時機與惰性置換(Lazy Swapper)機制。
  2. 工作集模型(Working Set Model)與框架分配(Frame Allocation):區域性原理(Principle of Locality)、抖動(Thrashing)防範與行程最小框架數決定因素。
  3. 系統抖動(Thrashing):定義與成因(頁面置換時間遠高於 CPU 實際執行時間)。
  4. 頁表(Page Table):虛擬位址至實體位址的轉譯映射(Virtual Address to Physical Address Mapping)。
  5. 貝拉迪異常(Bélády's Anomaly):特定分頁置換演算法下,框架數增加卻導致頁面錯誤率上升的特例現象。

解題方法

本題為經典的作業系統概念複選題,解題切入點為將各選項敘述與經典教科書(Operating System Concepts by Silberschatz)中的標準定義進行比對:

  1. 基本定義比對:確認 (a)、(c)、(d)、(e) 是否精準符合 Demand Paging、Thrashing、Page Table 及 Bélády's Anomaly 的教科書定義。
  2. 關鍵觀念辨析(選項 (b) 陷阱處理):
    • 行程執行的最少框架數(Minimum number of frames):由硬體的**指令集架構(Instruction Set Architecture, ISA)**決定(例如:必須確保單一指令及其定址模式存取記憶體時有足夠的框架數使指令順利完成)。
    • 工作集模型(Working Set Model):用於估算行程當前的區域性大小(Locality size)並據此動態分配框架,其目的在於防止系統發生抖動(Prevent Thrashing),而非決定硬體層面避免頁面錯誤所需的最少框架數。

選項分析

  • (a) Demand paging is a technique that brings a page into memory only when it is needed.
    【正確】
    請求分頁(Demand Paging)的核心機制為「惰性置換(Lazy Swapping)」,即在行程執行過程中,唯有當某一頁面真正被存取(needed / referenced)且產生頁面缺失(Page Fault)時,作業系統才會將該頁面從輔助記憶體(如磁碟)載入至實體記憶體中。未被存取的頁面絕不會預先載入。

  • (b) The working set model helps determine the minimum number of frames required to avoid page faults.
    【錯誤】
    此選項混淆了作業系統中的兩個概念:

    1. 最少框架數(Minimum Number of Frames):行程執行所需的「最少框架數」係由**指令集架構(ISA)**所決定(例如完成單一指令執行與間接定址所需的最少記憶體位址數),而非 Working Set Model。
🔒

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

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

免費註冊

第 5 題10 分

  1. (10pts, no partial point, no penalty) Which of the following statement about CPU scheduling is/are TRUE?
    (a) Round Robin scheduling assigns each process a fixed time slice, known as a quantum.
    (b) Priority scheduling allows a higher-priority process to preempt a lower-priority process.
    (c) The Shortest Job Next (SJN) scheduling algorithm minimizes the total processing time.
    (d) Aging is a technique used to prevent the "starvation" of low-priority processes in priority scheduling.
    (e) Multilevel Queue scheduling organizes processes into multiple priority levels and uses a fixed time quantum for each level.

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

這一題的完整詳解

核心觀念

本題考驗作業系統(Operating Systems)中 CPU 排程(CPU Scheduling) 的基本概念與各類排程演算法特性的比較,包含:

  1. Round Robin (RR) 排程 的時間分片(Time Quantum / Time Slice)機制。
  2. Priority Scheduling(優先權排程) 的搶佔(Preemption)特性與 Starvation(飢餓) 問題。
  3. Aging(老化機制) 對於解除 Starvation 的作用。
  4. Shortest Job Next (SJN / SJF) 的最佳化目標(最小化平均等待時間而非總處理時間)。
  5. Multilevel Queue (MLQ,多層佇列排程) 之佇列結構與各自採用的排程策略。

解題方法

針對每一項 CPU 排程觀念,檢視其定義、運作機制及效能指標:

  1. 區分效能指標:注意「平均等待時間(Average Waiting Time)」與「總處理時間(Total Processing Time / Execution Time)」的差異。
  2. 釐清排程特性:區分單一佇列與多層佇列的機制,以及搶佔式(Preemptive)與非搶佔式(Non-preemptive)排程的允許行為。
  3. 識別關鍵技術:掌握解決無限期等待(Indefinite Blocking)的標準做法(如 Aging)。

選項分析

  • (a) 正確。
    Round Robin (RR) 排程演算法專為分時系統 (Time-Sharing Systems) 設計。系統會指定一個固定的時間單位,稱為時間量子 (Time Quantum) 或時間分片 (Time Slice),通常落在 10 ms10 \text{ ms} 到 100 ms100 \text{ ms} 之間。CPU 依序分配給 Ready Queue 中的每一個 Process,當 Process 執行時間達到一個 Time Quantum 後即會被搶佔 (Preempted),並放回 Ready Queue 尾端等待下一輪分配。

  • (b) 正確。
    Priority Scheduling 可以分為搶佔式 (Preemptive) 與非搶佔式 (Non-preemptive)。在搶佔式優先權排程中,當一個具備更高優先權的 Process 到達 Ready Queue 時,系統允許 (allows) 其中斷並搶佔正在 CPU 上執行的低優先權 Process。因此「優先權排程允許高優先權 Process 搶佔低優先權 Process」之敘述完全符合其機制特性。

  • (c) 錯誤。
    Shortest Job Next (SJN,又稱 Shortest Job First, SJF) 的數學特性是可以證明達到最小化的**平均等待時間 (Average Waitin

🔒

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

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

免費註冊

第 6 題10 分

  1. (10pts, no partial point, no penalty) Which of the following statements about RISC-V and MIPS ISA is/are TRUE?
    (a) RISC-V has fixed instruction lengths, all of them are 32 bits, to simplify decoding and execution.
    (b) RISC-V support both little-endian and big-endian memory storage.
    (c) MIPS is a CISC (Complex Instruction Set Computing) architecture.
    (d) The MIPS architecture follows a load-store architecture.
    (e) x86 is an example of a RISC architecture.

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

這一題的完整詳解

核心觀念

本題考查**指令集架構(Instruction Set Architecture, ISA)**的基本分類與設計特徵,主要比較 RISC(精簡指令集電腦) 與 CISC(複雜指令集電腦),以及 RISC-V 與 MIPS 兩大代表性 RISC 架構的規範細節:

  1. RISC 與 CISC 之分類:
    • RISC (Reduced Instruction Set Computer):代表架構包含 MIPS、RISC-V、ARM。設計特色為指令簡化、格式規整、注重流水線(Pipelining)執行效率。
    • CISC (Complex Instruction Set Computing):代表架構為 x86 (IA-32, x86-64)。設計特色為指令豐富且複雜、變數長度編碼、支援複雜的定址模式。
  2. Load-Store 架構(載入/儲存架構):
    • 又稱為 Register-Register 架構。在此架構下,所有算術與邏輯運算指令(ALU Operations)的運算元必須來自暫存器(Register),運算結果也寫回暫存器。
    • 存取記憶體(Memory)的動作被嚴格限制在專用的載入指令(Load,如 lw)與儲存指令(Store,如 sw),不允許算術指令直接操作記憶體內容。
  3. 指令長度與擴充性:
    • 傳統 RISC(如經典 MIPS)採用固定 32 位元長度指令以簡化解碼邏輯。
    • 現代 RISC(如 RISC-V)基礎指令集為 32 位元,但模組化規範明確支援變長度指令擴充(如 16 位元的精簡指令擴充 Compressed Extension, RVC)。
  4. 位元組順序(Endianness):
    • 記憶體中多位元組資料的儲存順序分為小端序(Little-Endian)與大端序(Big-Endian)。支援兩種模式的架構稱為雙端序(Bi-endian)。

解題方法

解題切入點為依據 RISC-V 與 MIPS 的標準教科書(如 Patterson & Hennessy《Computer Organization and Design》)及官方 ISA 規範,逐一比對各選項敘述之真偽:

  1. 檢視 RISC-V 是否限制為固定 32 位元長度。
  2. 檢視 RISC-V 規範對端序(Endianness)的支援定義。
  3. 判定 MIPS 屬於 RISC 還是 CISC 架構。
  4. 判定 MIPS 是否符合 Load-Store 架構定義。
  5. 判定 x86 屬於 RISC 還是 CISC 架構。

選項分析

  • (a) 錯誤
    • 選項原文:RISC-V has fixed instruction lengths, all of them are 32 bits, to simplify decoding and execution.
    • 詳細說明:RISC-V 的基礎指令集(如 RV32I、RV64I)之指令長度確實為 3232 位元,但 RISC-V 架構在設計之初即規劃了變長度指令(Variable-length Instructions)的支援。
🔒

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

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

免費註冊

第 7 題10 分

  1. (10pts, no partial point, no penalty) Which of the following statements about dynamic linking is/are TRUE?
    (a) In dynamic linking, if a shared library is updated, all programs using that library need to be recompiled.
    (b) The process of dynamic linking occurs entirely at runtime, not at compile-time.
    (c) Dynamic linking is more suitable for embedded systems with limited resources compared to static linking.
    (d) Dynamic linking is limited to certain operating systems and is not widely supported across different platforms.
    (e) In dynamic linking, the entire content of the shared library is loaded into memory, even if only a small portion of it is used by the program.

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

這一題的完整詳解

核心觀念

本題考驗作業系統與計算機組織中**動態連結(Dynamic Linking)與靜態連結(Static Linking)**的核心機制差異。主要涵蓋以下觀念:

  1. 鏈結時點(Binding Time / Linking Time):

    • 靜態連結:在編譯/靜態連結期(Compile/Link Time),連結器(Linker)將所有目標檔(.o / .obj)與靜態函式庫(.a / .lib)組合,將所有函式位址直接寫死(Hardcode)或完成重定位,打包成單一獨立的執行檔。
    • 動態連結:將函式庫的連結過程延後。編譯/靜態連結期僅在執行檔內寫入**存根程式碼(Stub)與符號重定位表(如 PLT/GOT);真正的函式庫載入與符號位址綁定,則交由動態連結器(Dynamic Linker/Loader,如 Linux 的 ld.so)在載入期(Load Time)或執行期(Run Time / Lazy Binding)**完成。
  2. 獨立更新性(Independent Updatability)與代碼共享(Code Sharing):

    • 共享函式庫(Shared Library,如 .so、.dll、.dylib)在實體記憶體中僅需存有一份唯讀的指令頁面(Text Segment),即可供多個進程(Processes)共享。
    • 當共享函式庫更新時,只要應用程式介面(API / ABI)未改變,應用程式無需重新編譯即可直接享有修正與優化。
  3. 需求分頁(Demand Paging)機制:

    • 現代作業系統將動態函式庫透過 mmap 對映至進程的虛擬位址空間。只有當程式執行並實際觸發**缺頁中斷(Page Fault)**時,作業系統才會將對應的分頁(Page)載入實體記憶體(RAM),而非一次性載入整個函式庫。

解題方法

本題為敘述觀念辨析題,切入點為針對每個選項檢視其對「動態連結」機制的描述是否符合實務與理論定義:

  1. 檢查動態連結在更新共享函式庫時的重新編譯需求(評估選項 (a))。
  2. 劃分動態連結在編譯期(Compile-time)與載入/執行期(Load/Run-time)各自承擔的工作(評估選項 (b))。
  3. 比較靜態連結與動態連結在資源受限環境(嵌入式系統)的優劣(評估選項 (c))。
  4. 檢視動態連結在現代主流作業系統的跨平台支援廣泛度(評估選項 (d))。
  5. 結合虛擬記憶體的需求分頁機制,分析共享函式庫載入實體記憶體的行為(評估選項 (e))。

選項分析

  • (a) 敘述錯誤。
    動態連結的最大優點之一為獨立維護與更新。當共享函式庫(Shared Library)修補漏洞或優化內部實作時,只要函式介面與二進位介面(ABI)保持相容,所有使用該函式庫的程式均不需要重新編譯或重新連結,在下次啟動執行時即可自動載入最新版本的函式庫。若需重新編譯則失去了動態連結的主要意義。

  • (b) 敘述錯誤。
    動態連結的處理過程並非完全(entirely)發生在執行期。動態連結是一個跨越多個階段的協同過程:

    1. 編譯/靜態連結期(Compile/Link-Time):靜態連結器仍需進行符號檢查,確認引用的動態函式存在,並在產生的執行檔中嵌入動態連結資訊、存根程式碼(Stub)、程序連結表(Procedure Linkage Table, PLT)與全域偏移表(Global Offset Table, GOT)。
🔒

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

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

免費註冊

第 8 題10 分

  1. (10pts, no partial point, no penalty) Virtual memory is a technique that uses main memory as a "cache" for secondary storage. Which of the following statement about cache is/are TRUE?
    (a) Write-back cache writes data to the main memory immediately after each write operation, ensuring that the cache and main memory are always in sync.
    (b) A direct-mapped cache allows multiple cache lines to map to the same set, reducing the likelihood of cache conflicts and improving overall cache performance.
    (c) In a fully-associative cache, each memory block can be placed in any cache line, minimizing the need for replacement policies and making cache management simpler.
    (d) Least Recently Used (LRU) is a cache replacement policy that evicts the cache line containing the data that has not been accessed for the longest period.

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

這一題的完整詳解

核心觀念

本題考查計算機組織與架構(Computer Organization and Architecture)中**快取記憶體(Cache Memory)**的基本設計原理,涵蓋以下四大核心主題:

  1. 快取寫入策略(Cache Write Policies):Write-through(直寫法)與 Write-back(寫回法)的運作時機與資料同步機制。
  2. 快取映射架構(Cache Mapping Schemes):Direct-mapped(直接映射)、Set-associative(組聯想)與 Fully-associative(全聯想)的組(Set)與列(Line)結構差異。
  3. 快取置換策略(Cache Replacement Policies):置換演算法的必要性及其硬體實現複雜度。
  4. LRU 演算法(Least Recently Used):置換策略的精確定義與執行邏輯。

解題方法

依據快取記憶體的標準規範與定義,逐一檢視各選項之描述是否符合電腦系統架構設計:

  1. 分析寫入策略:區分「每次寫入皆更新主記憶體」與「唯有區塊被剔除時才更新主記憶體」的差異。
  2. 分析映射結構:檢視 Direct-mapped 快取的容量與結構配置,區分每組(Set)所包含的快取列數(Lines per set)。
  3. 分析全聯想快取特性:評估區塊任意放置(Any location)對於搜尋標籤(Tag Search)、置換演算法需求及硬體控制複雜度的影響。
  4. 驗證 LRU 定義:確認最近最少使用演算法之挑選基準(Access Time)。

選項分析

  • (a) 錯誤

    • 原文原文:Write-back cache writes data to the main memory immediately after each write operation, ensuring that the cache and main memory are always in sync.
    • 詳細解析:每次執行寫入操作時「立即將資料寫回主記憶體(Main Memory)」以確保快取與主記憶體隨時同步的機制稱為 Write-through(直寫法)。相反地,**Write-back(寫回法)**在快取命中寫入時僅更新快取內部的資料,並將該區塊對應的 Dirty Bit(髒位元)設為 11;只有當該被修改過的 Dirty 區塊因快取額滿而被剔除(Evict/Replace)時,才會一次性寫回主記憶體。
  • (b) 錯誤

    • 原文:A direct-mapped cache allows multiple cache lines to map to the same set, reducing the likelihood of cache conflicts and improving overall cache performance.
    • 詳細解析:在 Direct-mapped 快取中,每一個 Set 僅包含恰好 11 條 Cache Line(即 11-way Set-associative)。
🔒

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

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

免費註冊

第 9 題10 分

  1. (10pts) Let's multiply the binary numbers 101011 and 110110 using Booth's Algorithm. Let Q = 101011 be multiplicand and M = 110110 be multiplier.
    (a) Calculate the number of additions needed during the process.
    (b) Calculate the number of subtractions needed during the process.

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

這一題的完整詳解

在 Booth 演算法中,於每一個週期檢查 (Q0,Q−1)(Q_0,Q_{-1}) 的兩位組合:

{00或 11:不做任何運算01:加上 M10:減去 M\begin{cases} 00\text{或 }11 &: \text{不做任何運算}\\ 01 &: \text{加上 }M\\ 10 &: \text{減去 }M \end{cases}

題目給定

Q=101011(被乘數)M=110110(乘數)Q = 101011 \quad(\text{被乘數})\qquad M = 110110 \quad(\text{乘數})

演算時以 M 為 multiplier,將其 LSB 依序與前一位 Q−1Q_{-1}(初始為 0)配對:

🔒

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

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

免費註冊

第 9 題10 分

  1. (10pts) Let's multiply the binary numbers 101011 and 110110 using Booth's Algorithm. Let Q = 101011 be multiplicand and M = 110110 be multiplier.
    (a) Calculate the number of additions needed during the process.
    (b) Calculate the number of subtractions needed during the process.

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

這一題的完整詳解

核心觀念

本題考查計算機組織中的 布斯演算法(Booth's Algorithm, Radix-2)。該演算法專為二進位有號數(二補數,2's complement)乘法設計,能有效處理正數與負數乘法,並減少加減法次數。

  1. 運算規則:
    設乘數(Multiplier)為 M=mn−1mn−2…m1m0M = m_{n-1} m_{n-2} \dots m_1 m_0,最右側需擴充一位附加位元 m−1=0m_{-1} = 0。在每個週期中,檢視相鄰位元對 (mi,mi−1)(m_i, m_{i-1}) 以決定對累加器(Accumulator, ACAC)執行的算術動作:

    • (mi,mi−1)=002(m_i, m_{i-1}) = 00_2:不做加減法,僅執行算術右移(Arithmetic Right Shift, ASR)。
    • (mi,mi−1)=012(m_i, m_{i-1}) = 01_2:累加器加上被乘數(AC←AC+QAC \leftarrow AC + Q),隨後執行算術右移。
    • (mi,mi−1)=102(m_i, m_{i-1}) = 10_2:累加器減去被乘數(AC←AC−QAC \leftarrow AC - Q),隨後執行算術右移。
    • (mi,mi−1)=112(m_i, m_{i-1}) = 11_2:不做加減法,僅執行算術右移。
  2. 布斯重新編碼(Booth Recoding):
    對應的運算權重可表示為 yi=mi−1−miy_i = m_{i-1} - m_i:

    • yi=+1  ⟹  y_i = +1 \implies 執行 1 次加法(Addition)
    • yi=−1  ⟹  y_i = -1 \implies 執行 1 次減法(Subtraction)
    • yi=0  ⟹  y_i = 0 \implies 不執行加減法

解題方法

1. 變數設定

  • 被乘數(Multiplicand):Q=1010112Q = 101011_2(6 位元,二補數十進位值為 −21-21)
  • 乘數(Multiplier):M=1101102M = 110110_2(6 位元,二補數十進位值為 −10-10)
  • 初始累加器:AC=0000002AC = 000000_2(6 位元)
  • 附加位元:m−1=0m_{-1} = 0
  • 總運算週期數:乘數長度 n=6n = 6,故需執行 6 個週期。

2. 位元對分析與加減法判定(Booth Recoding 法)

將乘數位元序列與附加位元排列為 m5m4m3m2m1m0∣m−1=110110∣0m_5 m_4 m_3 m_2 m_1 m_0 \mid m_{-1} = 110110 \mid 0。
自右向左檢視各週期的相鄰位元對 (mi,mi−1)(m_i, m_{i-1}):

  • 週期 1 (i=0i=0):檢查 (m0,m−1)=(0,0)  ⟹  (m_0, m_{-1}) = (0, 0) \implies 不執行加減法(僅右移)。
  • 週期 2 (i=1i=1):檢查 (m1,m0)=(1,0)  ⟹  (m_1, m_0) = (1, 0) \implies 執行 1 次減法(AC←AC−QAC \leftarrow AC - Q)。
  • 週期 3 (i=2i=2):檢查 (m2,m1)=(1,1)  ⟹  (m_2, m_1) = (1, 1) \implies 不執行加減法(僅右移)。
  • 週期 4 (i=3i=3):檢查 (m3,m2)=(0,1)  ⟹  (m_3, m_2) = (0, 1) \implies 執行 1 次加法(AC←AC+QAC \leftarrow AC + Q)。
  • 週期 5 (i=4i=4):檢查 (m4,m3)=(1,0)  ⟹  (m_4, m_3) = (1, 0) \implies 執行 1 次減法(AC←AC−QAC \leftarrow AC - Q)。
  • 週期 6 (i=5i=5):檢查 (m5,m4)=(1,1)  ⟹  (m_5, m_4) = (1, 1) \implies 不執行加減法(僅右移)。

統計結果:

  • 加法次數((0,1)(0, 1) 出現次數)=1= 1 次。
  • 減法次數((1,0)(1, 0) 出現次數)=2= 2 次。

3. 完整暫存器追蹤(Register Trace)與結果驗算

被乘數 Q=1010112Q = 101011_2(−21-21),減去 QQ 等同於加上其二補數負值 −Q=0101012-Q = 010101_2(+21+21)。

週期 (Cycle)位元對 (mi,mi−1)(m_i, m_{i-1})算術動作 (Operation)ACAC 暫存器MM 暫存器m−1m_{-1}
🔒

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

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

免費註冊

第 10 題10 分

  1. (10pts) Consider a computer system with an associative cache. The cache has a total size of 32 KB, and each cache line can store 64 bytes of data. If the cache uses a 4-way set-associative mapping, calculate the following:
    (a) The size of each set in Byte.
    (b) The size of the tag field in bits, assuming a 32-bit memory address.

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

這一題的完整詳解

核心觀念

本題考查計算機組織(Computer Organization)中**快取記憶體對映(Cache Mapping)與記憶體位址切分(Memory Address Decomposition)**的核心原理。主要涵蓋以下概念與公式:

  1. 組相聯快取(Set-Associative Cache)結構:

    • 快取由數個集合(Set)組成,每個集合包含 NN 個快取行/區塊(Cache Line / Block),稱為 NN-way 組相聯。
    • 集合大小(Set Size in Bytes):一個集合所能儲存的資料總容量,公式為:
      Set Size=N×Block Size\text{Set Size} = N \times \text{Block Size}
    • 集合總數(Number of Sets, SS):
      S=Cache Total SizeSet Size=Cache Total SizeN×Block SizeS = \frac{\text{Cache Total Size}}{\text{Set Size}} = \frac{\text{Cache Total Size}}{N \times \text{Block Size}}
  2. 記憶體位址劃分(Address Fields):
    在位址總線長度為 MM 位元(bits)的系統中,實體位址會被拆解為三個主要欄位 [Tag∣Index∣Offset][\text{Tag} \mid \text{Index} \mid \text{Offset}]:

    • 區塊位移(Offset bits):用來定址區塊內部的特定位元組(Byte),位元數等於 log⁡2(Block Size)\log_2(\text{Block Size})。
    • 索引欄位(Index bits):用來指定資料存放在哪一個集合(Set),位元數等於 log⁡2(S)\log_2(S)。
    • 標籤欄位(Tag bits):用來比對該區塊是否為目標主記憶體資料,計算公式為:
      Tag bits=M−Index bits−Offset bits\text{Tag bits} = M - \text{Index bits} - \text{Offset bits}

解題步驟與推導

由題目給定已知條件:

  • 快取總容量(Cache Size, CC)=32 KB=32×1024 Bytes=215 Bytes= 32\text{ KB} = 32 \times 1024\text{ Bytes} = 2^{15}\text{ Bytes}
  • 區塊/快取行大小(Block Size / Line Size, BB)=64 Bytes=26 Bytes= 64\text{ Bytes} = 2^6\text{ Bytes}
  • 相聯度(Associativity, NN)=4= 4-way(即 1 個 Set 包含 4 個 Line)
  • 主記憶體位址長度(Address Size, MM)=32 bits= 32\text{ bits}

(a) 計算每個 Set 的大小(單位:Byte)

  1. 根據 NN-way 組相聯定義,每個集合(Set)包含 N=4N = 4 個快取行。
  2. 每個快取行可儲存 B=64 BytesB = 64\text{ Bytes} 資料。
  3. 因此,每個集合的大小為:
    Set Size=N×B=4×64 Bytes=256 Bytes\text{Set Size} = N \times B = 4 \times 64\text{ Bytes} = 256\text{ Bytes}

(b) 計算 Tag 欄位的長度(單位:bit)

  1. 計算 Offset 位元數:
    Offset bits=log⁡2(B)=log⁡2(64)=6 bits\text{Offset bits} = \log_2(B) = \log_2(64) = 6\text{ bits}
  2. 計算集合總數(SS)與 Index 位元數:
🔒

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

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

免費註冊

其他考古題