ITM 201

Microprocessor and Computer Architecture

TU BIM · Semester 3 · BIM curriculum effective from 2021

Requirement
required
Credits
3
Past papers
2 papers

Past exam papers

Complete papers are arranged by exam year (BS / AD) and model paper.

past exam papers loaded.

Tribhuvan University

Faculty of Management

Office of the Dean

Official Model Question Paper / Dean's Office Blueprint

Course: ITM 201 · Microprocessor and Computer Architecture

Level: Bachelor of Information Management (BIM) · Semester 3

Full Marks: 60

Time: 3 hrs.

Candidates are required to give their answers in their own words as far as practicable. The figures in the margin indicate full marks.

Group A

Brief Answer Questions. Attempt ALL questions.

[5 × 2 = 10]
  1. Distinguish between von Neumann Architecture and Harvard Architecture in terms of memory bus structure.

    [2]
    View model solution

    Answer:

    Parameter von Neumann Architecture Harvard Architecture
    Bus Structure Single shared bus for conveying both instructions and data between CPU and memory. Separate physical buses for instructions (instruction bus) and data (data bus).
    Memory Space Unified memory address space storing both code and data. Separate physical memory address spaces for program instructions and data.
    Bottleneck von Neumann Bottleneck: Instruction fetch and data read/write cannot occur simultaneously. High throughput: CPU can fetch an instruction and read/write data concurrently.
    Typical Usage General-purpose microprocessors (x86, ARM desktop). Digital Signal Processors (DSP), Microcontrollers (PIC, AVR).
  2. What is an Addressing Mode? Explain Immediate Addressing and Register Indirect Addressing with 8085/8086 assembly examples.

    [2]
    View model solution

    Answer:

    • Addressing Mode: The rule or technique by which the CPU interprets an instruction’s operand field to locate the effective memory address of the required data.
    • Immediate Addressing: The actual operand data is specified directly within the instruction itself. 8085 Example: MVI A, 45H (Loads immediate hex byte 45H directly into Accumulator).
    • Register Indirect Addressing: The instruction specifies a register pair that holds the physical memory address where the operand is stored. 8085 Example: MOV A, M (Loads Accumulator with data from memory address pointed by the HL register pair).
  3. Describe the operational functions of the Program Counter (PC) and the Stack Pointer (SP) in CPU architecture.

    [2]
    View model solution

    Answer:

    • Program Counter (PC): A 16-bit internal register that holds the memory address of the next instruction to be fetched and executed. It is automatically incremented as instructions are fetched sequentially, or updated during branch/jump instructions.
    • Stack Pointer (SP): A 16-bit register that stores the memory address of the current top of the LIFO (Last-In, First-Out) stack structure in RAM. It decrements when data is pushed (PUSH or subroutine CALL) and increments when data is popped (POP or RET).
  4. Define Cache Hit, Cache Miss, and the mathematical formula for the Cache Hit Ratio (HH).

    [2]
    View model solution

    Answer:

    • Cache Hit: Occurs when the memory word or block requested by the CPU is already present in cache memory, allowing immediate retrieval at high speed (thitt_{\text{hit}}).
    • Cache Miss: Occurs when the requested memory word is absent from cache, requiring an access to slower main RAM (imposing a miss penalty).
    • Hit Ratio (HH): The fraction of total memory references satisfied by the cache:
      H=Number of Cache HitsTotal Memory References  (Hits+Misses)H = \frac{\text{Number of Cache Hits}}{\text{Total Memory References} \; (\text{Hits} + \text{Misses})}
      Miss ratio is M=1HM = 1 - H.
  5. What is an Interrupt? Differentiate between Maskable Interrupts and Non-Maskable Interrupts (NMI) in microprocessors.

    [2]
    View model solution

    Answer:

    • Interrupt: An asynchronous hardware or software signal that suspends the CPU’s normal program execution sequence, saves context, and forces execution of an Interrupt Service Routine (ISR).
    • Maskable Interrupt: An interrupt whose servicing can be enabled or disabled/ignored by software commands (e.g. EI / DI instructions in 8085; e.g., RST 7.5, RST 6.5, INTR). Used for normal peripheral I/O.
    • Non-Maskable Interrupt (NMI): An interrupt that the CPU cannot ignore or mask under any software condition (e.g., TRAP in 8085). Reserved for catastrophic events like power failure or hardware memory parity faults.

Group B

Descriptive Answer Questions. Attempt any THREE questions.

[3 × 10 = 30]
  1. Analyze the internal architecture of the Intel 8085 Microprocessor: a) Draw and describe its functional block diagram: Register array (B, C, D, E, H, L), Accumulator, ALU, Status Flags, and Timing/Control Unit. (5 Marks) b) Write a complete 8085 assembly language program to find the maximum number in an array of NN bytes stored in memory starting from address 2050H. Store the largest value at address 3050H. Provide a register trace. (5 Marks)

    [10]
    View model solution

    8085 Microprocessor Architecture and Maximum Number Assembly Program

    a) 8085 Functional Internal Architecture

    1. Functional Units
    1. Arithmetic and Logic Unit (ALU): Performs 8-bit arithmetic (add, subtract) and logical (AND, OR, XOR, compare) operations.
    2. Accumulator (Register A): 8-bit register serving as the primary source operand and destination for all ALU results.
    3. General Purpose Registers: Six 8-bit registers (B,C,D,E,H,LB, C, D, E, H, L) that can function individually or as 16-bit register pairs (BC,DE,HLBC, DE, HL) where HLHL serves as the default memory pointer MM.
    4. Flags Register (F): 5 flip-flops recording arithmetic status:
      • S (Sign): Set if MSB (D7D_7) is 1 (negative).
      • Z (Zero): Set if ALU result is exactly zero.
      • AC (Auxiliary Carry): Set on carry from bit D3D_3 to D4D_4 (for BCD).
      • P (Parity): Set if result contains even number of 1s.
      • CY (Carry): Set on arithmetic overflow/carry beyond bit D7D_7.
    5. Timing and Control Unit: Decodes instructions and generates synchronization pulses (ALE, RD, WR, IO/M).

    b) 8085 Assembly Language Program: Find Maximum Value

    ; Problem: Find maximum byte in array of length N
    ; Array length N stored at: 2050H
    ; Array data starts at:    2051H
    ; Store maximum result at: 3050H
    
              LXI H, 2050H    ; HL points to array count N
              MOV C, M        ; Load counter C with array size N
              INX H           ; HL points to first array element (2051H)
              MOV A, M        ; Initialize Accumulator with first element
              DCR C           ; Decrement counter (1 element already processed)
              JZ STORE        ; If array had only 1 element, jump to store
    
    LOOP:     INX H           ; HL points to next element
              CMP M           ; Compare Accumulator with memory element M
                              ; If A >= M: Carry flag CY = 0
                              ; If A < M:  Carry flag CY = 1
              JNC SKIP        ; If A >= M, do not replace, skip
              MOV A, M        ; If A < M, load new maximum into Accumulator
    
    SKIP:     DCR C           ; Decrement remaining elements counter
              JNZ LOOP        ; Repeat until all elements examined
    
    STORE:    STA 3050H       ; Store maximum value in memory address 3050H
              HLT             ; Terminate program execution
    
    Step-by-Step Register Trace
    • Let array at 2050H contain: Count N=3N = 3, elements: [25H, 64H, 12H].
    Instruction Executed Reg A Reg C Reg HL Carry Flag (CY) Comment
    LXI H, 2050H -- -- 2050H -- Pointer initialized
    MOV C, M -- 03H 2050H -- Counter C=3C = 3
    INX H -- 03H 2051H -- Pointer to first item
    MOV A, M 25H 03H 2051H -- Initial max A=25HA = 25H
    DCR C 25H 02H 2051H 0 Count C=2C = 2
    INX H 25H 02H 2052H 0 Points to 64H
    CMP M 25H 02H 2052H 1 25H<64H    CY=125H < 64H \implies CY=1
    MOV A, M 64H 02H 2052H 1 New max A=64HA = 64H
    DCR C 64H 01H 2052H 0 Count C=1C = 1
    INX H 64H 01H 2053H 0 Points to 12H
    CMP M 64H 01H 2053H 0 64H12H    CY=064H \ge 12H \implies CY=0
    JNC SKIP 64H 01H 2053H 0 Skips replacement
    DCR C 64H 00H 2053H 0 Counter C=0    C = 0 \implies Loop ends
    STA 3050H 64H 00H 2053H 0 Memory 3050H receives 64H
  2. Explain the concept of an Instruction Pipeline: a) Detail the 5 stages of a classic RISC instruction pipeline (IF, ID, EX, MEM, WB). (4 Marks) b) Analyze the three primary classes of pipeline hazards: Structural Hazards, Data Hazards (RAW, WAR, WAW), and Control Hazards. Explain techniques used to eliminate each hazard. (4 Marks) c) Calculate the theoretical pipeline speedup for executing n=1000n = 1000 instructions on a k=5k = 5 stage pipeline with clock cycle τ=2 ns\tau = 2\text{ ns} compared to an unpipelined processor requiring 10 ns per instruction. (2 Marks)

    [10]
    View model solution

    Instruction Pipelining, Hazard Analysis, and Speedup Calculation

    a) 5-Stage Classic RISC Instruction Pipeline

    1. IF (Instruction Fetch): The instruction pointed to by the PC is fetched from memory/I-Cache into the Instruction Register (IR); PC is incremented.
    2. ID (Instruction Decode / Register Fetch): The instruction opcode is decoded in the control logic; source operands are read from the register file.
    3. EX (Execute / ALU): ALU performs the arithmetic operation, computes memory effective address for loads/stores, or evaluates branch conditions.
    4. MEM (Memory Access): Data memory or D-Cache is accessed to read (load) or write (store) data operands.
    5. WB (Write Back): The resulting data from ALU or memory is written back to the destination register in the register file.

    b) Pipeline Hazards and Mitigation Techniques

    1. Structural Hazards
    • Cause: Hardware resource conflict when two pipeline stages attempt to access the exact same physical hardware component in the same clock cycle. Example: IF stage fetching instruction from RAM while MEM stage is simultaneously reading data from RAM.
    • Remedy: Separate instruction and data caches (Harvard memory split) or duplicating hardware execution units.
    2. Data Hazards

    Occur when an instruction depends on the result of a previous instruction that is still in flight in the pipeline:

    • RAW (Read After Write - True Dependency): Instruction jj tries to read a register before instruction ii writes to it. Remedy: Operand Forwarding (Bypassing) routes ALU output directly from EX/MEM stage registers to the EX stage of the next instruction without waiting for WB; or inserting software/hardware pipeline stalls (bubbles).
    • WAR (Write After Read - Anti-dependency): Occurs in out-of-order execution when jj tries to write before ii reads.
    • WAW (Write After Write - Output dependency): Occurs when jj overwrites a register before an earlier instruction ii writes. Remedy for WAR/WAW: Register Renaming.
    3. Control Hazards (Branch Hazards)
    • Cause: Conditional branches change the PC, but the branch outcome and target address are not resolved until the EX/MEM stage, during which incorrect sequential instructions have already been fetched.
    • Remedy: Branch Prediction (Dynamic 2-bit saturating branch history tables), Delayed Branching with branch delay slots.

    c) Pipeline Speedup Calculation

    • Number of stages k=5k = 5
    • Number of instructions n=1000n = 1000
    • Pipelined clock cycle τk=2 ns\tau_k = 2\text{ ns}
    • Unpipelined execution time per instruction τu=10 ns\tau_u = 10\text{ ns}
    1. Total Unpipelined Time (TuT_u)
    Tu=n×τu=1000×10 ns=10,000 nsT_u = n \times \tau_u = 1000 \times 10\text{ ns} = 10,000\text{ ns}
    2. Total Pipelined Time (TkT_k)

    The first instruction takes kk cycles to fill the pipe; the remaining (n1)(n - 1) instructions complete at the rate of 1 instruction per cycle:

    Tk=(k+n1)×τk=(5+10001)×2 ns=1004×2 ns=2,008 nsT_k = (k + n - 1) \times \tau_k = (5 + 1000 - 1) \times 2\text{ ns} = 1004 \times 2\text{ ns} = 2,008\text{ ns}

    3. Speedup (SS)
    S=TuTk=10,000 ns2,008 ns4.98S = \frac{T_u}{T_k} = \frac{10,000\text{ ns}}{2,008\text{ ns}} \approx \mathbf{4.98}

    The 5-stage pipeline achieves a near-ideal 4.98×4.98\times speedup.

  3. Analyze Cache Memory Organization and Address Mapping: a) Compare Direct Mapping, Associative Mapping, and Set-Associative Mapping. (5 Marks) b) A system has a 32-bit byte-addressable main memory and a 64 KB 4-way Set-Associative Cache with a block size of 64 bytes. Determine the exact bit allocation for the Tag, Set Index, and Word (Block) Offset fields of the memory address. (5 Marks)

    [10]
    View model solution

    Cache Mapping Techniques and Set-Associative Address Partitioning

    a) Comparison of Cache Mapping Techniques

    Parameter Direct Mapping Associative (Fully Associative) Set-Associative Mapping
    Placement Rule Block jj can map to strictly one cache line: i=j(modlines)i = j \pmod{\text{lines}}. Block jj can be placed into any arbitrary line in the cache. Cache is divided into sets; block jj can be placed into any line within set: s=j(modsets)s = j \pmod{\text{sets}}.
    Hardware Complexity Lowest; requires only 1 comparator per lookup. Highest; requires simultaneous parallel comparators for every line. Moderate; requires kk comparators for a kk-way set-associative cache.
    Conflict Misses High; multiple blocks competing for the same line trigger thrashing. Zero conflict misses (only capacity and compulsory misses). Significantly reduced conflict misses; balances speed and hit rate.

    b) Mathematical Address Bit Allocation Calculation

    1. System Parameters
    • Total Address Space: 32 bits (2322^{32} bytes = 4 GB byte-addressable memory)
    • Cache Size = 64 KB=64×1024 bytes=65,536 bytes=216 bytes64\text{ KB} = 64 \times 1024\text{ bytes} = 65,536\text{ bytes} = 2^{16}\text{ bytes}
    • Block Size (Line Size) = 64 bytes=26 bytes64\text{ bytes} = 2^6\text{ bytes}
    • Set Associativity (kk) = 4-way (k=4=22k = 4 = 2^2 lines per set)
    2. Block (Word) Offset Calculation

    The block offset determines the exact byte within a 64-byte cache block:

    Block Offset Bits=log2(Block Size)=log2(64)=log2(26)=6 bits\text{Block Offset Bits} = \log_2(\text{Block Size}) = \log_2(64) = \log_2(2^6) = \mathbf{6\text{ bits}}

    3. Set Index Calculation

    Total number of lines in cache:

    Total Lines=Cache SizeBlock Size=65,536 bytes64 bytes=1024 lines=210\text{Total Lines} = \frac{\text{Cache Size}}{\text{Block Size}} = \frac{65,536\text{ bytes}}{64\text{ bytes}} = 1024\text{ lines} = 2^{10}

    Total number of sets in a 4-way set-associative cache:

    Number of Sets=Total Linesk=10244=256 sets=28\text{Number of Sets} = \frac{\text{Total Lines}}{k} = \frac{1024}{4} = 256\text{ sets} = 2^8

    Set Index Bits=log2(Number of Sets)=log2(256)=log2(28)=8 bits\text{Set Index Bits} = \log_2(\text{Number of Sets}) = \log_2(256) = \log_2(2^8) = \mathbf{8\text{ bits}}
    4. Tag Bits Calculation

    The remaining most significant bits constitute the Tag:

    Tag Bits=Total Address Bits(Set Index Bits+Block Offset Bits)\text{Tag Bits} = \text{Total Address Bits} - (\text{Set Index Bits} + \text{Block Offset Bits})
    Tag Bits=32(8+6)=3214=18 bits\text{Tag Bits} = 32 - (8 + 6) = 32 - 14 = \mathbf{18\text{ bits}}

    5. 32-Bit Memory Address Partitioning Map
    Field Name Tag Set Index Block Offset
    Bit Width 18 bits 8 bits 6 bits
    Bit Range Bits 31 down to 14 Bits 13 down to 6 Bits 5 down to 0

    Total check: 18+8+6=3218 + 8 + 6 = 32 bits.

  4. Examine Input/Output Organization and Direct Memory Access (DMA): a) Contrast Programmed I/O, Interrupt-Driven I/O, and Direct Memory Access (DMA) with respect to CPU utilization and data transfer speed. (5 Marks) b) Describe the functional architecture of a DMA Controller (e.g. Intel 8237). Detail the bus handshake signals (HOLD and HLDA) and contrast Burst Mode versus Cycle Stealing Mode of data transfer. (5 Marks)

    [10]
    View model solution

    I/O Organization and Direct Memory Access (DMA) Mechanics

    a) Comparison of I/O Transfer Techniques

    Parameter Programmed I/O Interrupt-Driven I/O Direct Memory Access (DMA)
    CPU Involvement Continuous Polling: CPU is trapped in a tight loop checking device status flags. Partial: CPU executes other tasks until device raises an interrupt request. Zero during transfer: Dedicated DMA controller manages entire bulk block transfer.
    CPU Utilization Extremely wasteful; CPU idle waiting for slow peripherals. Efficient; CPU only handles context switch and ISR execution. Maximum efficiency; CPU only initializes transfer registers.
    Transfer Speed Slow; bounded by polling loop cycle overhead. Moderate; bounded by interrupt latency and register pushing/popping. Wire-Speed: Maximum hardware bus transfer rates (essential for NVMe, Gigabit NICs).

    b) DMA Controller Architecture and Bus Handshake

    1. Core Internal Registers of DMA Controller (Intel 8237)
    • Memory Address Register: Stores the starting RAM memory address for data read/write. Increments after each byte transferred.
    • Byte Count Register: Stores the number of bytes to transfer. Decrements after each byte until reaching zero (Terminal Count - TC).
    • Control / Status Register: Configures transfer direction (Memory-to-I/O or I/O-to-Memory) and DMA channel priority.
    2. Bus Handshake Protocol (HOLD and HLDA)
    1. When a high-speed peripheral (e.g., Disk Controller) needs to transfer a block, it asserts DMA Request (DREQ).
    2. The DMA Controller asserts the HOLD line to the CPU, requesting complete ownership of the system address, data, and control buses.
    3. The CPU completes its current bus machine cycle, floats its buses into a high-impedance state, and replies with Hold Acknowledge (HLDA).
    4. The DMA controller asserts DACK to the peripheral and drives memory address and read/write control lines directly, transferring data directly between peripheral and RAM without passing through CPU registers.
    5. Upon transferring the final byte, the DMA Controller drops HOLD, and the CPU resumes normal bus control.
    3. Data Transfer Modes
    • Burst Mode (Block Transfer): The DMA controller retains continuous control of system buses until the entire block of data is completely transferred. Delivers maximum transfer speed, but locks the CPU out of main memory for prolonged intervals.
    • Cycle Stealing Mode: The DMA controller acquires the bus, transfers exactly one byte/word, and immediately relinquishes the bus back to the CPU. It “steals” idle CPU memory cycles, allowing CPU execution and high-speed I/O to interleave seamlessly without starving the processor.

Group C

Comprehensive Answer / Case Analysis Question. Attempt ALL questions.

[1 × 20 = 20]
  1. Computer Architecture Case Study: High-Reliability Smart Electric Grid Telemetry Station

    Nepal Electricity Authority (NEA) is engineering an embedded telemetry microprocessor node for automated substation monitoring across the Kaligandaki transmission corridor. The microcontroller processes real-time 3-phase AC voltage and current sensor samples to detect dangerous grid surges:

    • Performance & Real-Time Constraints: The telemetry node samples 16 ADC channels at 50 kHz. Incoming sensor data generates 3.2 MB of raw waveform data per second.
    • Memory Hierarchy Challenges: The processor runs at a core frequency of 200 MHz (5 ns5\text{ ns} cycle). Main off-chip DRAM has an access latency of 60 ns. To prevent buffer overflows, the system incorporates a split Level 1 (L1) Cache and a unified Level 2 (L2) Cache.
    • Telemetry Latency: When a transmission line flashover or grid surge occurs, the system must trigger an electrical trip breaker within less than 500 nanoseconds via a prioritized hardware interrupt.

    Questions: a) Formulate the core processor architecture. Contrast 32-bit RISC versus CISC design choices for this real-time embedded monitoring system, detailing register file sizing, instruction cycle predictability, and hardware DSP multiplication support. (6 Marks) b) Design and optimize the memory hierarchy. Given:

    • L1 Cache latency tL1=1 cycle (5 ns)t_{L1} = 1\text{ cycle } (5\text{ ns}), Hit Ratio H1=95%H_1 = 95\%
    • L2 Cache latency tL2=4 cycles (20 ns)t_{L2} = 4\text{ cycles } (20\text{ ns}), Local Hit Ratio H2=90%H_2 = 90\%
    • Main DRAM latency tRAM=12 cycles (60 ns)t_{\text{RAM}} = 12\text{ cycles } (60\text{ ns}) Formulate the Average Memory Access Time (AMAT) mathematical equation, compute the exact AMAT in nanoseconds, and evaluate the Write-Back versus Write-Through cache coherency policy for high-speed sensor streams. (7 Marks) c) Design the I/O subsystem, DMA channel architecture, and real-time interrupt handling: Explain how a circular dual-buffer DMA configuration allows continuous ADC sampling without CPU intervention, and specify the Vectored Priority Interrupt Controller (NVIC) configuration ensuring sub-500ns trip breaker response. (7 Marks)
    [20]
    View model solution

    Computer Architecture Solution: Smart Electric Grid Telemetry Node

    a) Core Processor Architecture: Embedded RISC vs. CISC Selection

    1. Architectural Selection: 32-Bit RISC (ARM Cortex-M / RISC-V RV32IMF)
    • Deterministic Instruction Timing: RISC architectures feature fixed-length 32-bit instructions executing in uniform, single-cycle or predictable pipelined stages. In power grid safety systems, deterministic execution is critical for real-time fault guarantees; CISC variable-length instructions (1 to 15 bytes in x86) cause unpredictable instruction decoding jitter.
    • Register File Sizing (32 General-Purpose 32-bit Registers): A large orthogonal register file (R0R31R_0 - R_{31}) minimizes memory spills. Time-critical sensor variables, Fast Fourier Transform (FFT) coefficients, and threshold limits are pinned permanently inside CPU registers.
    • Hardware DSP / Single-Cycle MAC (Multiply-Accumulate): Real-time RMS voltage calculation requires continuous quadratic summation (Vi2\sum V_i^2). A hardware single-cycle MAC unit computes AA+(X×Y)A \leftarrow A + (X \times Y) in 5 ns5\text{ ns}, processing sensor streams without CPU stalls.

    b) Memory Hierarchy Optimization and AMAT Calculation

    1. Average Memory Access Time (AMAT) Formulation

    For a two-level cache hierarchy, AMAT is:

    AMAT=tL1+(1H1)×(tL2+(1H2)×tRAM)\text{AMAT} = t_{L1} + (1 - H_1) \times \left( t_{L2} + (1 - H_2) \times t_{\text{RAM}} \right)
    where:

    • tL1=5 nst_{L1} = 5\text{ ns} (1 clock cycle)
    • H1=0.95    Miss Rate M1=10.95=0.05H_1 = 0.95 \implies \text{Miss Rate } M_1 = 1 - 0.95 = 0.05
    • tL2=20 nst_{L2} = 20\text{ ns} (4 clock cycles)
    • H2=0.90    Local Miss Rate M2=10.90=0.10H_2 = 0.90 \implies \text{Local Miss Rate } M_2 = 1 - 0.90 = 0.10
    • tRAM=60 nst_{\text{RAM}} = 60\text{ ns} (12 clock cycles)
    2. Step-by-Step AMAT Calculation
    1. L2 Miss Penalty to DRAM:
      PenaltyL2=tL2+(1H2)×tRAM=20 ns+(0.10×60 ns)=20 ns+6 ns=26 ns\text{Penalty}_{L2} = t_{L2} + (1 - H_2) \times t_{\text{RAM}} = 20\text{ ns} + (0.10 \times 60\text{ ns}) = 20\text{ ns} + 6\text{ ns} = \mathbf{26\text{ ns}}
    2. Overall AMAT:
      AMAT=tL1+(1H1)×PenaltyL2\text{AMAT} = t_{L1} + (1 - H_1) \times \text{Penalty}_{L2}
      AMAT=5 ns+(0.05×26 ns)=5 ns+1.3 ns=6.30 ns\text{AMAT} = 5\text{ ns} + (0.05 \times 26\text{ ns}) = 5\text{ ns} + 1.3\text{ ns} = \mathbf{6.30\text{ ns}}
    • Conclusion: Cache hierarchy reduces effective memory access latency from 60 ns60\text{ ns} down to 6.30 ns6.30\text{ ns}—a 9.52×9.52\times memory access speedup!
    3. Cache Write Policy: Write-Back with Dirty Bit
    • Write-Through: Every write must update both cache and main DRAM. At 3.2 MB/s continuous ADC input, Write-Through saturates the 60ns DRAM bus, creating severe bus contention stalls.
    • Write-Back (Selected): Writes update only the high-speed L1/L2 cache blocks. A Dirty Bit flags modified lines; data is written back to DRAM only when a cache line is evicted. This isolates the CPU and DMA from slow DRAM latency during steady-state monitoring.

    c) DMA Subsystem and Sub-500ns Interrupt Architecture

    1. Circular Ping-Pong (Dual Buffer) DMA Configuration
    [16-Channel ADC]
           |
           v (Hardware DREQ trigger)
    [DMA Controller Channel 0]
           |
           +---> [Buffer A (RAM)] ---> Processed by CPU (FFT & Surge Algorithm)
           |
           +---> [Buffer B (RAM)] ---> Concurrently filled by DMA (Zero CPU overhead)
    
    • Ping-Pong Buffer Mechanism: While the DMA engine autonomously writes incoming ADC samples into Buffer A, the CPU processes completed waveform samples in Buffer B.
    • When Buffer A fills, DMA controller asserts a half-transfer interrupt and automatically flips write pointers to Buffer B. Zero CPU cycles are wasted copying sensor bytes.
    2. Nested Vectored Interrupt Controller (NVIC) for Sub-500ns Response

    To guarantee breaker trip under 500 ns500\text{ ns}:

    1. Zero-Latency Hardware Vectoring: The hardware surge comparator output is wired directly to Interrupt Line 0 (highest priority NMI). The NVIC hardware fetches the ISR address directly from the vector table in hardware without software polling.
    2. Hardware Register Stacking: In ARM Cortex-M, the processor hardware automatically pushes caller registers (R0R3,R12,LR,PC,xPSRR_0-R_3, R_{12}, LR, PC, xPSR) onto the stack in 12 clock cycles (12×5 ns=60 ns12 \times 5\text{ ns} = 60\text{ ns}).
    3. Dedicated Trip Breaker ISR Execution:
      • At t=60 nst = 60\text{ ns}, CPU enters ISR.
      • Executes single-cycle atomic GPIO set instruction: *GPIO_BSRR = (1 << TRIP_PIN); (5 ns5\text{ ns}).
      • Total latency from physical fault detection to breaker trip pulse is <100 ns< 100\text{ ns}, well within the stringent 500 ns500\text{ ns} safety requirement.