# CHAPTER 4: PROCESSOR FUNDAMENTALS

## 4.1 CENTRAL PROCESSING UNIT (CPU) ARCHITECTURE

### 4.1.1 Von Neumann Model

**Key Concept:**

- Data and programs are indistinguishable
- Can use the same memory for both
- Uses a single processor
- Follows fetch-decode-execute cycle

**Components:**

- Processor (CPU)
- Memory (for data and instructions)
- Input/Output devices

### 4.1.2 Registers

**Definition:** The smallest unit of storage in a microprocessor; allows fast data transfer.

**General Purpose Registers:**

- Used to temporarily store data values
- Can be used by assembly language instructions
- Example: Accumulator (ACC)

**Special Purpose Registers:**

<div class="sc-fYRIQK gLjTUz table-wrapper" id="bkmrk-register-function-pc" style="box-sizing: border-box; font-weight: 400; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; position: relative; color: rgb(0, 0, 0); font-family: "', Ubuntu, -apple-system, 'system-ui', 'Segoe UI', system-ui, Roboto, Oxygen, Cantarell, 'Open Sans', 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji"; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><table style="box-sizing: border-box; font-weight: normal; border-image: none 100% / 1 / 0 stretch; margin: 2em 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); text-indent: 0px; border-collapse: separate; -webkit-tap-highlight-color: transparent; --table-border-radius: 8px; font-size: 0.9em; width: 647px; border-radius: 8px; overflow: hidden; border-spacing: 0px; border: 0.5px solid rgba(0, 0, 0, 0.098);"><thead style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;"><tr style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;"><th style="box-sizing: border-box; font-weight: 600; border-width: 0px 0.5px 0.5px 0px; border-style: solid; border-color: oklch(0.92 0.004 286.32) rgba(0, 0, 0, 0.098) rgba(0, 0, 0, 0.098) oklch(0.92 0.004 286.32); border-image: initial; margin: 0px; padding: 0.5em; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; background-color: rgb(238, 238, 238); text-align: left;">Register</th><th style="box-sizing: border-box; font-weight: 600; border-top: 0px solid oklch(0.92 0.004 286.32); border-right: none; border-bottom: 0.5px solid rgba(0, 0, 0, 0.098); border-left: 0px solid oklch(0.92 0.004 286.32); border-image: initial; margin: 0px; padding: 0.5em; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; background-color: rgb(238, 238, 238); text-align: left;">Function</th></tr></thead><tbody style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;"><tr style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;"><td style="box-sizing: border-box; font-weight: normal; border-width: 0px 0.5px 0.5px 0px; border-style: solid; border-color: oklch(0.92 0.004 286.32) rgba(0, 0, 0, 0.098) rgba(0, 0, 0, 0.098) oklch(0.92 0.004 286.32); border-image: initial; margin: 0px; padding: 0.5em; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;">**PC (Program Counter)**</td><td style="box-sizing: border-box; font-weight: normal; border-top: 0px solid oklch(0.92 0.004 286.32); border-right: none; border-bottom: 0.5px solid rgba(0, 0, 0, 0.098); border-left: 0px solid oklch(0.92 0.004 286.32); border-image: initial; margin: 0px; padding: 0.5em; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;">Holds address of next instruction</td></tr><tr style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;"><td style="box-sizing: border-box; font-weight: normal; border-width: 0px 0.5px 0.5px 0px; border-style: solid; border-color: oklch(0.92 0.004 286.32) rgba(0, 0, 0, 0.098) rgba(0, 0, 0, 0.098) oklch(0.92 0.004 286.32); border-image: initial; margin: 0px; padding: 0.5em; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;">**MDR (Memory Data Register)**</td><td style="box-sizing: border-box; font-weight: normal; border-top: 0px solid oklch(0.92 0.004 286.32); border-right: none; border-bottom: 0.5px solid rgba(0, 0, 0, 0.098); border-left: 0px solid oklch(0.92 0.004 286.32); border-image: initial; margin: 0px; padding: 0.5em; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;">Holds data fetched from memory</td></tr><tr style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;"><td style="box-sizing: border-box; font-weight: normal; border-width: 0px 0.5px 0.5px 0px; border-style: solid; border-color: oklch(0.92 0.004 286.32) rgba(0, 0, 0, 0.098) rgba(0, 0, 0, 0.098) oklch(0.92 0.004 286.32); border-image: initial; margin: 0px; padding: 0.5em; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;">**MAR (Memory Address Register)**</td><td style="box-sizing: border-box; font-weight: normal; border-top: 0px solid oklch(0.92 0.004 286.32); border-right: none; border-bottom: 0.5px solid rgba(0, 0, 0, 0.098); border-left: 0px solid oklch(0.92 0.004 286.32); border-image: initial; margin: 0px; padding: 0.5em; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;">Holds address of memory cell to access</td></tr><tr style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;"><td style="box-sizing: border-box; font-weight: normal; border-width: 0px 0.5px 0.5px 0px; border-style: solid; border-color: oklch(0.92 0.004 286.32) rgba(0, 0, 0, 0.098) rgba(0, 0, 0, 0.098) oklch(0.92 0.004 286.32); border-image: initial; margin: 0px; padding: 0.5em; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;">**ACC (Accumulator)**</td><td style="box-sizing: border-box; font-weight: normal; border-top: 0px solid oklch(0.92 0.004 286.32); border-right: none; border-bottom: 0.5px solid rgba(0, 0, 0, 0.098); border-left: 0px solid oklch(0.92 0.004 286.32); border-image: initial; margin: 0px; padding: 0.5em; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;">Holds values processed by ALU</td></tr><tr style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;"><td style="box-sizing: border-box; font-weight: normal; border-width: 0px 0.5px 0.5px 0px; border-style: solid; border-color: oklch(0.92 0.004 286.32) rgba(0, 0, 0, 0.098) rgba(0, 0, 0, 0.098) oklch(0.92 0.004 286.32); border-image: initial; margin: 0px; padding: 0.5em; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;">**IX (Index Register)**</td><td style="box-sizing: border-box; font-weight: normal; border-top: 0px solid oklch(0.92 0.004 286.32); border-right: none; border-bottom: 0.5px solid rgba(0, 0, 0, 0.098); border-left: 0px solid oklch(0.92 0.004 286.32); border-image: initial; margin: 0px; padding: 0.5em; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;">Stores number to modify address</td></tr><tr style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;"><td style="box-sizing: border-box; font-weight: normal; border-width: 0px 0.5px 0.5px 0px; border-style: solid; border-color: oklch(0.92 0.004 286.32) rgba(0, 0, 0, 0.098) rgba(0, 0, 0, 0.098) oklch(0.92 0.004 286.32); border-image: initial; margin: 0px; padding: 0.5em; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;">**CIR (Current Instruction Register)**</td><td style="box-sizing: border-box; font-weight: normal; border-top: 0px solid oklch(0.92 0.004 286.32); border-right: none; border-bottom: 0.5px solid rgba(0, 0, 0, 0.098); border-left: 0px solid oklch(0.92 0.004 286.32); border-image: initial; margin: 0px; padding: 0.5em; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;">Holds current instruction for decoding</td></tr><tr style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;"><td style="box-sizing: border-box; font-weight: normal; border-top: 0px solid oklch(0.92 0.004 286.32); border-right: 0.5px solid rgba(0, 0, 0, 0.098); border-bottom: none; border-left: 0px solid oklch(0.92 0.004 286.32); border-image: initial; margin: 0px; padding: 0.5em; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;">**Status Register**</td><td style="box-sizing: border-box; font-weight: normal; border-top: 0px solid oklch(0.92 0.004 286.32); border-right: none; border-bottom: none; border-left: 0px solid oklch(0.92 0.004 286.32); border-image: initial; margin: 0px; padding: 0.5em; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;">Holds results of comparisons, arithmetic flags</td></tr></tbody></table>

<div class="sc-MHKXp dNlhAz table-toolbar" style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; position: absolute; top: 8px; right: 8px; z-index: 10; display: flex; gap: 4px; border-radius: 4px; opacity: 0; transition: opacity 0.2s; transform: translateZ(0px); will-change: opacity;">  
</div></div>### 4.1.3 CPU Components

**ALU (Arithmetic and Logic Unit):**

- Part of processor that processes instructions
- Performs arithmetic operations (add, subtract, multiply, divide)
- Performs logical operations (AND, OR, NOT)

**Control Unit (CU):**

- Fetches instructions from memory
- Decodes instructions
- Synchronizes operations
- Sends signals to memory, ALU, and I/O devices

**System Clock:**

- Timing device connected to processor
- Synchronizes all components
- Generates clock pulses

**IAS (Immediate Access Store):**

- Memory unit the processor can directly access

### 4.1.4 Buses

**Definition:** Set of parallel wires allowing data transfer between components.

**Data Bus:**

- Bidirectional
- Carries data between processor, memory, and I/O devices

**Address Bus:**

- Unidirectional
- Carries memory address from processor to MAR

**Control Bus:**

- Bidirectional
- Transmits control signals from CU
- Ensures components don't conflict

### 4.1.5 Performance Factors

**Clock Speed:**

- Number of pulses the clock sends in a given time
- Usually measured in GHz
- Higher clock speed = more cycles per second = faster execution
- Limitation: Heat generation at high speeds

**Bus Width:**

- Number of bits that can be transferred simultaneously
- Wider bus = more bits transferred at once = faster processing

**Cache Memory:**

- Stores commonly used instructions
- Larger cache = more instructions stored = less waiting = better performance

**Number of Cores:**

- Multi-core processors have multiple processing units
- Each core can process different instructions simultaneously
- Improves performance through parallel processing

### 4.1.6 Ports

<div class="sc-fYRIQK gLjTUz table-wrapper" id="bkmrk-port-type-descriptio" style="box-sizing: border-box; font-weight: 400; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; position: relative; color: rgb(0, 0, 0); font-family: "', Ubuntu, -apple-system, 'system-ui', 'Segoe UI', system-ui, Roboto, Oxygen, Cantarell, 'Open Sans', 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji"; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><table style="box-sizing: border-box; font-weight: normal; border-image: none 100% / 1 / 0 stretch; margin: 2em 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); text-indent: 0px; border-collapse: separate; -webkit-tap-highlight-color: transparent; --table-border-radius: 8px; font-size: 0.9em; width: 647px; border-radius: 8px; overflow: hidden; border-spacing: 0px; border: 0.5px solid rgba(0, 0, 0, 0.098);"><thead style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;"><tr style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;"><th style="box-sizing: border-box; font-weight: 600; border-width: 0px 0.5px 0.5px 0px; border-style: solid; border-color: oklch(0.92 0.004 286.32) rgba(0, 0, 0, 0.098) rgba(0, 0, 0, 0.098) oklch(0.92 0.004 286.32); border-image: initial; margin: 0px; padding: 0.5em; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; background-color: rgb(238, 238, 238); text-align: left;">Port Type</th><th style="box-sizing: border-box; font-weight: 600; border-top: 0px solid oklch(0.92 0.004 286.32); border-right: none; border-bottom: 0.5px solid rgba(0, 0, 0, 0.098); border-left: 0px solid oklch(0.92 0.004 286.32); border-image: initial; margin: 0px; padding: 0.5em; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; background-color: rgb(238, 238, 238); text-align: left;">Description</th></tr></thead><tbody style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;"><tr style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;"><td style="box-sizing: border-box; font-weight: normal; border-width: 0px 0.5px 0.5px 0px; border-style: solid; border-color: oklch(0.92 0.004 286.32) rgba(0, 0, 0, 0.098) rgba(0, 0, 0, 0.098) oklch(0.92 0.004 286.32); border-image: initial; margin: 0px; padding: 0.5em; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;">**USB**</td><td style="box-sizing: border-box; font-weight: normal; border-top: 0px solid oklch(0.92 0.004 286.32); border-right: none; border-bottom: 0.5px solid rgba(0, 0, 0, 0.098); border-left: 0px solid oklch(0.92 0.004 286.32); border-image: initial; margin: 0px; padding: 0.5em; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;">Connects input and output devices</td></tr><tr style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;"><td style="box-sizing: border-box; font-weight: normal; border-width: 0px 0.5px 0.5px 0px; border-style: solid; border-color: oklch(0.92 0.004 286.32) rgba(0, 0, 0, 0.098) rgba(0, 0, 0, 0.098) oklch(0.92 0.004 286.32); border-image: initial; margin: 0px; padding: 0.5em; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;">**HDMI**</td><td style="box-sizing: border-box; font-weight: normal; border-top: 0px solid oklch(0.92 0.004 286.32); border-right: none; border-bottom: 0.5px solid rgba(0, 0, 0, 0.098); border-left: 0px solid oklch(0.92 0.004 286.32); border-image: initial; margin: 0px; padding: 0.5em; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;">High-definition video and audio output</td></tr><tr style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;"><td style="box-sizing: border-box; font-weight: normal; border-top: 0px solid oklch(0.92 0.004 286.32); border-right: 0.5px solid rgba(0, 0, 0, 0.098); border-bottom: none; border-left: 0px solid oklch(0.92 0.004 286.32); border-image: initial; margin: 0px; padding: 0.5em; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;">**VGA**</td><td style="box-sizing: border-box; font-weight: normal; border-top: 0px solid oklch(0.92 0.004 286.32); border-right: none; border-bottom: none; border-left: 0px solid oklch(0.92 0.004 286.32); border-image: initial; margin: 0px; padding: 0.5em; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;">Video output only (older displays)</td></tr></tbody></table>

<div class="sc-MHKXp dNlhAz table-toolbar" style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; position: absolute; top: 8px; right: 8px; z-index: 10; display: flex; gap: 4px; border-radius: 4px; opacity: 0; transition: opacity 0.2s; transform: translateZ(0px); will-change: opacity;">  
</div></div>### 4.1.7 Fetch-Execute Cycle

**Fetch Stage:**

1. PC holds address of next instruction
2. Address copied to MAR
3. PC incremented
4. Instruction loaded to MDR from address in MAR
5. Instruction from MDR loaded to CIR

**Decode Stage:**

- Opcode and operand parts identified

**Execute Stage:**

- Control unit executes instruction
- Return to start

**Register Transfer Notation (RTN):**

<div class="sc-zOxLx iJoNFs code-block" id="bkmrk-%3Ctext%3E-mar-%E2%86%90-%5Bpc%5D-pc" style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; position: relative; width: 647px; min-width: 35ch;"><div class="sc-cgHfjM iurpwe" style="box-sizing: border-box; font-weight: bold; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px 10px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; display: flex; align-items: center; color: rgb(0, 0, 0); font-size: 14px; line-height: 1; border-top-left-radius: 8px; border-top-right-radius: 8px; height: 34px; background-color: rgb(238, 238, 238);">&lt;TEXT&gt;</div><div class="sc-iQqcaB jMJkfu" style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; position: sticky; top: 28px; z-index: 10;"><div class="sc-kcLKEh sc-dntSTA sc-dFVmKS sc-fcSHUR kIsGeY jNoXSY cklChQ kmrhIw code-toolbar" style="box-sizing: border-box; font-weight: normal; border: none; margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; width: auto; height: 24px; flex: 0 0 auto; inset: auto 0.5rem 0.3rem auto; opacity: 0; border-radius: 4px; gap: 4px; display: flex; justify-content: flex-start; align-items: center; flex-direction: row; position: absolute; background-color: rgb(238, 238, 238); transition: opacity 0.2s; transform: translateZ(0px); will-change: opacity;">  
</div></div><div class="sc-fpikKz lhQggy split-view-wrapper" style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; display: flex; border-radius: 0px 0px 8px 8px;"><div class="shiki one-light code-viewer source-view shiki-light" style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; font-family: "', 'Cascadia Code', 'Fira Code", Consolas, Menlo, Courier, monospace; line-height: initial; --color-scrollbar-thumb: rgba(0, 0, 0, 0.15); --color-scrollbar-thumb-hover: rgba(0, 0, 0, 0.2); flex: 1 1 auto; width: 647px; border-radius: inherit; background-color: rgb(250, 250, 250); color: rgb(56, 58, 66);"><div class="sc-jCWzJg ednTDb shiki-scroller" style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0.5em 0px 0.5em 1em; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; display: block; overflow: auto hidden; position: relative; border-radius: inherit; --gutter-width: 0ch; font-size: 13px;"><div class="shiki-list" style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; height: 147px; width: 634px; position: relative;"><div style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; position: absolute; top: 0px; left: 0px; width: 634px; transform: translateY(0px);"><div data-index="0" style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;"><div class="line" style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; display: flex; align-items: flex-start; width: 634px; line-height: 21px; contain: none; will-change: auto;"><span class="line-content" style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px 1em 0px 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; white-space: pre; flex: 1 1 0%;"><span style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; white-space: pre; overflow-wrap: normal;">MAR ← \[PC\]</span></span></div></div><div data-index="1" style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;"><div class="line" style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; display: flex; align-items: flex-start; width: 634px; line-height: 21px; contain: none; will-change: auto;"><span class="line-content" style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px 1em 0px 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; white-space: pre; flex: 1 1 0%;"><span style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; white-space: pre; overflow-wrap: normal;">PC ← \[PC\] + 1</span></span></div></div><div data-index="2" style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;"><div class="line" style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; display: flex; align-items: flex-start; width: 634px; line-height: 21px; contain: none; will-change: auto;"><span class="line-content" style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px 1em 0px 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; white-space: pre; flex: 1 1 0%;"><span style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; white-space: pre; overflow-wrap: normal;">MDR ← \[\[MAR\]\]</span></span></div></div><div data-index="3" style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;"><div class="line" style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; display: flex; align-items: flex-start; width: 634px; line-height: 21px; contain: none; will-change: auto;"><span class="line-content" style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px 1em 0px 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; white-space: pre; flex: 1 1 0%;"><span style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; white-space: pre; overflow-wrap: normal;">CIR ← \[MDR\]</span></span></div></div><div data-index="4" style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;"><div class="line" style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; display: flex; align-items: flex-start; width: 634px; line-height: 21px; contain: none; will-change: auto;"><span class="line-content" style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px 1em 0px 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; white-space: pre; flex: 1 1 0%;"><span style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; white-space: pre; overflow-wrap: normal;">Decode</span></span></div></div><div data-index="5" style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;"><div class="line" style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; display: flex; align-items: flex-start; width: 634px; line-height: 21px; contain: none; will-change: auto;"><span class="line-content" style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px 1em 0px 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; white-space: pre; flex: 1 1 0%;"><span style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; white-space: pre; overflow-wrap: normal;">Execute</span></span></div></div><div data-index="6" style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;"><div class="line" style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; display: flex; align-items: flex-start; width: 634px; line-height: 21px; contain: none; will-change: auto;"><span class="line-content" style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px 1em 0px 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; white-space: pre; flex: 1 1 0%;"><span style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; white-space: pre; overflow-wrap: normal;">Return to start</span></span></div></div></div></div></div></div></div></div>### 4.1.8 Interrupts

**Definition:** A signal from a program seeking the processor's attention.

**ISR (Interrupt Service Routine):**

- Handles the interrupt
- Different ISRs for different sources

**Interrupt Handling Process:**

1. Processor checks interrupt register at end of F-E cycle
2. If interrupt flag is set, source detected
3. If low priority, interrupt disabled
4. If high priority: 
    - Save register contents to stack
    - Load PC with ISR address
    - Execute ISR
    - Restore registers from stack
    - Continue interrupted program

---

## 4.2 ASSEMBLY LANGUAGE

### 4.2.1 Introduction

**Assembly Language:**

- Low-level programming language
- Instructions consist of opcode and operand

**Machine Code:**

- Binary code the processor executes directly
- One-to-one relationship with assembly language

**Assembler:**

- Software that translates assembly language to machine code
- Replaces mnemonics and labels with binary values

### 4.2.2 Assembler Types

**One-Pass Assembler:**

- Converts source code in one sweep
- Cannot handle forward referencing

**Two-Pass Assembler:**

**Pass 1:**

- Creates symbol table
- Enters symbolic addresses and labels

**Pass 2:**

- Translates to machine code using table
- Reports errors

### 4.2.3 Addressing Modes

<div class="sc-fYRIQK gLjTUz table-wrapper" id="bkmrk-mode-description-imm" style="box-sizing: border-box; font-weight: 400; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; position: relative; color: rgb(0, 0, 0); font-family: "', Ubuntu, -apple-system, 'system-ui', 'Segoe UI', system-ui, Roboto, Oxygen, Cantarell, 'Open Sans', 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji"; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><table style="box-sizing: border-box; font-weight: normal; border-image: none 100% / 1 / 0 stretch; margin: 2em 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); text-indent: 0px; border-collapse: separate; -webkit-tap-highlight-color: transparent; --table-border-radius: 8px; font-size: 0.9em; width: 647px; border-radius: 8px; overflow: hidden; border-spacing: 0px; border: 0.5px solid rgba(0, 0, 0, 0.098);"><thead style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;"><tr style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;"><th style="box-sizing: border-box; font-weight: 600; border-width: 0px 0.5px 0.5px 0px; border-style: solid; border-color: oklch(0.92 0.004 286.32) rgba(0, 0, 0, 0.098) rgba(0, 0, 0, 0.098) oklch(0.92 0.004 286.32); border-image: initial; margin: 0px; padding: 0.5em; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; background-color: rgb(238, 238, 238); text-align: left;">Mode</th><th style="box-sizing: border-box; font-weight: 600; border-top: 0px solid oklch(0.92 0.004 286.32); border-right: none; border-bottom: 0.5px solid rgba(0, 0, 0, 0.098); border-left: 0px solid oklch(0.92 0.004 286.32); border-image: initial; margin: 0px; padding: 0.5em; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; background-color: rgb(238, 238, 238); text-align: left;">Description</th></tr></thead><tbody style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;"><tr style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;"><td style="box-sizing: border-box; font-weight: normal; border-width: 0px 0.5px 0.5px 0px; border-style: solid; border-color: oklch(0.92 0.004 286.32) rgba(0, 0, 0, 0.098) rgba(0, 0, 0, 0.098) oklch(0.92 0.004 286.32); border-image: initial; margin: 0px; padding: 0.5em; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;">**Immediate**</td><td style="box-sizing: border-box; font-weight: normal; border-top: 0px solid oklch(0.92 0.004 286.32); border-right: none; border-bottom: 0.5px solid rgba(0, 0, 0, 0.098); border-left: 0px solid oklch(0.92 0.004 286.32); border-image: initial; margin: 0px; padding: 0.5em; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;">Data is the actual value (e.g., LDM #n)</td></tr><tr style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;"><td style="box-sizing: border-box; font-weight: normal; border-width: 0px 0.5px 0.5px 0px; border-style: solid; border-color: oklch(0.92 0.004 286.32) rgba(0, 0, 0, 0.098) rgba(0, 0, 0, 0.098) oklch(0.92 0.004 286.32); border-image: initial; margin: 0px; padding: 0.5em; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;">**Direct**</td><td style="box-sizing: border-box; font-weight: normal; border-top: 0px solid oklch(0.92 0.004 286.32); border-right: none; border-bottom: 0.5px solid rgba(0, 0, 0, 0.098); border-left: 0px solid oklch(0.92 0.004 286.32); border-image: initial; margin: 0px; padding: 0.5em; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;">Load contents at given address (e.g., LDD address)</td></tr><tr style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;"><td style="box-sizing: border-box; font-weight: normal; border-width: 0px 0.5px 0.5px 0px; border-style: solid; border-color: oklch(0.92 0.004 286.32) rgba(0, 0, 0, 0.098) rgba(0, 0, 0, 0.098) oklch(0.92 0.004 286.32); border-image: initial; margin: 0px; padding: 0.5em; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;">**Indirect**</td><td style="box-sizing: border-box; font-weight: normal; border-top: 0px solid oklch(0.92 0.004 286.32); border-right: none; border-bottom: 0.5px solid rgba(0, 0, 0, 0.098); border-left: 0px solid oklch(0.92 0.004 286.32); border-image: initial; margin: 0px; padding: 0.5em; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;">Address to use is at given address (e.g., LDI address)</td></tr><tr style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;"><td style="box-sizing: border-box; font-weight: normal; border-width: 0px 0.5px 0.5px 0px; border-style: solid; border-color: oklch(0.92 0.004 286.32) rgba(0, 0, 0, 0.098) rgba(0, 0, 0, 0.098) oklch(0.92 0.004 286.32); border-image: initial; margin: 0px; padding: 0.5em; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;">**Indexed**</td><td style="box-sizing: border-box; font-weight: normal; border-top: 0px solid oklch(0.92 0.004 286.32); border-right: none; border-bottom: 0.5px solid rgba(0, 0, 0, 0.098); border-left: 0px solid oklch(0.92 0.004 286.32); border-image: initial; margin: 0px; padding: 0.5em; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;">Address = given address + contents of IX (e.g., LDX address)</td></tr><tr style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;"><td style="box-sizing: border-box; font-weight: normal; border-top: 0px solid oklch(0.92 0.004 286.32); border-right: 0.5px solid rgba(0, 0, 0, 0.098); border-bottom: none; border-left: 0px solid oklch(0.92 0.004 286.32); border-image: initial; margin: 0px; padding: 0.5em; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;">**Relative**</td><td style="box-sizing: border-box; font-weight: normal; border-top: 0px solid oklch(0.92 0.004 286.32); border-right: none; border-bottom: none; border-left: 0px solid oklch(0.92 0.004 286.32); border-image: initial; margin: 0px; padding: 0.5em; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;">Next instruction is offset from current instruction</td></tr></tbody></table>

<div class="sc-MHKXp dNlhAz table-toolbar" style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; position: absolute; top: 8px; right: 8px; z-index: 10; display: flex; gap: 4px; border-radius: 4px; opacity: 0; transition: opacity 0.2s; transform: translateZ(0px); will-change: opacity;">  
</div></div>### 4.2.4 Instruction Types

**Data Movement:**

- LDM#: Load immediate
- LDD: Load direct
- LDI: Load indirect
- LDX: Load indexed
- STO: Store

**Arithmetic:**

- ADD: Add to accumulator
- SUB: Subtract from accumulator
- INC: Increment
- DEC: Decrement

**Comparing:**

- CMP: Compare with contents at address
- CMP#: Compare with immediate value

**Conditional Jumps:**

- JPE: Jump if equal (compare TRUE)
- JPN: Jump if not equal (compare FALSE)

**Unconditional Jumps:**

- JMP: Jump to address

**I/O:**

- IN: Input character
- OUT: Output character

**End:**

- END: Return control to OS

---

## 4.3 BIT MANIPULATION

### 4.3.1 Binary Shifts

**Left Shift (LSL #n):**

- Bits shifted left
- Multiplies by 2ⁿ
- Zeros fill vacated positions

**Right Shift (LSR #n):**

- Bits shifted right
- Divides by 2ⁿ
- Zeros fill vacated positions

**Arithmetic Shift:**

- Used for signed integers
- Sign bit (MSB) maintained

**Cyclic Shift:**

- Bit removed from one end added to other end

### 4.3.2 Bit Masking

**Purpose:** Each bit can represent an individual flag. By manipulating bits, flags can be operated upon.

**Operations:**

**Masking to 1:**

- Use OR operation with 1

**Masking to 0:**

- Use AND operation with 0

**Testing Bits:**

- Use AND to mask bits
- Compare result with pattern

**Practical Applications:**

- Setting individual bit positions
- Testing specific bits
- Checking patterns