8085 Memory Paging, Processes, and Segmentation - ASCII Diagrams
Overview
This document contains comprehensive ASCII diagrams and text illustrations for memory paging, process management, and memory segmentation in 8085 microprocessor systems.
1. Complete Memory Segmentation Architecture
64 KB Total Memory
0000H - FFFFH
|
_________________|_________________
| | | | |
| | | | |
[SYSTEM] [RESERVED] [CODE] [DATA] [STACK] [UPPER]
| | | | | |
0000H 0100H 1000H 2000H 2FFFH 3000H
00FFH 0FFFH 1FFFH 2FFFH 3000H FFFFH
256B 3.75KB 4 KB 4 KB 1-4KB 52 KB
| | | | | |
----- ------- ------ ----- ------- -------
INTER OS/MONIT PROGRAM DATA TEMPORARY EXTENDED
RUPTS OR CODE STORAGE ROM/IO
❌DO NOT USUALLY ✓EXECUTE ✓READ/ LIFO Large
WRITE PROTECTED HERE WRITE GROWTH DATA
Key Points:
- System Reserved (0000H-00FFH): 256 bytes for interrupts and vectors
- Reserved Area (0100H-0FFFH): 3,840 bytes, OS/Monitor programs
- Code Segment (1000H-1FFFH): 4 KB for executable instructions
- Data Segment (2000H-2FFFH): 4 KB for variables and constants
- Stack Segment (2FFFH downward): 1-4 KB, LIFO structure
- Upper Memory (3000H-FFFFH): 52 KB, extended space/ROM/I/O
2. Memory Paging Concept
64 KB Memory
┌─────────────────────────────────────┐
│ PAGE 0: 0000H - 0FFFH (4 KB) │ System & Interrupts
├─────────────────────────────────────┤
│ PAGE 1: 1000H - 1FFFH (4 KB) │ Code & Program
├─────────────────────────────────────┤
│ PAGE 2: 2000H - 2FFFH (4 KB) │ Data & Stack
├─────────────────────────────────────┤
│ PAGE 3: 3000H - 3FFFH (4 KB) │ Extended Memory
├─────────────────────────────────────┤
│ PAGE 4: 4000H - 4FFFH (4 KB) │ Extended Memory
├─────────────────────────────────────┤
│ ... │ ...
├─────────────────────────────────────┤
│ PAGE 15: F000H - FFFFH (4 KB) │ Extended Memory
└─────────────────────────────────────┘
Total: 16 pages × 4 KB = 64 KB memory space
Paging Benefits:
- Fixed-size pages (4 KB each)
- Easy memory management
- Simple page replacement algorithms
- Reduced external fragmentation
- Virtual memory support
3. Process Management and Memory Layout
Operating System - Multi-Process Manager
┌─────────────────────────────────────────────────────┐
│ PROCESS 1 Status: RUNNING │
├─────────────────────────────────────────────────────┤
│ Code: 1000H - 1500H (1.25 KB) │
│ Data: 2000H - 2100H (256 B) │
│ Stack: 2FFFH downward (grows down) │
│ PID: 1 │
└─────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────┐
│ PROCESS 2 Status: WAITING │
├─────────────────────────────────────────────────────┤
│ Code: 1000H - 1400H (1 KB) │
│ Data: 2000H - 2200H (512 B) │
│ Stack: 2FFFH downward (grows down) │
│ PID: 2 │
└─────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────┐
│ PROCESS 3 Status: READY │
├─────────────────────────────────────────────────────┤
│ Code: 1000H - 1600H (1.5 KB) │
│ Data: 2000H - 2050H (80 B) │
│ Stack: 2FFFH downward (grows down) │
│ PID: 3 │
└─────────────────────────────────────────────────────┘
Each process has its own:
- Independent code segment
- Independent data segment
- Independent stack segment
- Process control block (PCB)
- Unique Process ID (PID)
4. Process States and Context Switching
Process Lifecycle
┌─────────────┐
│ NEW PROCESS│
│ CREATED │
└──────┬──────┘
│
▼
┌─────────────┐
│ READY │
│ STATE │◄──────┐
└──────┬──────┘ │
│ │
▼ │
┌─────────────┐ │
│ RUNNING │ │
│ STATE │ │
└──────┬──────┘ │
│ │
┌──────┴─────────────┴──────┐
│ CONTEXT SWITCH OR │
│ INTERRUPT OCCURS? │
│ YES │
└──────┬────────────────────┘
│
▼
┌──────────────────┐
│ SAVE CONTEXT: │
│ • All Registers │
│ • Stack Pointer │
│ • Program Counter│
│ • Processor Flags│
└──────┬───────────┘
│
▼
┌────────────────┐
│ SWITCH TO NEXT │
│ PROCESS │
└──────┬─────────┘
│
└──────────────┐
│
┌─────────────┐ │
│ COMPLETION │ │
│ PROCESS ENDS│ │
└─────────────┘ │
│
(LOOP BACK)
Context Saved During Switch:
- All Registers (A, B, C, D, E, H, L)
- Stack Pointer (SP)
- Program Counter (PC)
- Processor Flags (S, Z, AC, P, CY)
- Additional state information
5. Memory Addressing in Segmented Architecture
Logical Address to Physical Address Translation
┌─────────────────────────────────────────────────────┐
│ LOGICAL ADDRESS (Process View) │
│ ┌───────────────────────┐ │
│ │ Segment Base: 1000H │ │
│ │ Offset: 0100H │ │
│ │ Logical Addr: 1000H + 0100H = 1100H │
│ └───────────────────────┘ │
└────────────────┬────────────────────────────────────┘
│
▼
┌────────────────────────┐
│ MEMORY MANAGEMENT UNIT │
│ - Segment Table Lookup │
│ - Address Translation │
│ - Protection Check │
└────────────┬───────────┘
│
▼
┌──────────────────────────┐
│ PHYSICAL ADDRESS │
│ (Actual RAM Location) │
│ = 1100H (in this case) │
└──────────┬───────────────┘
│
▼
┌──────────────────────────┐
│ ACCESS MEMORY │
│ Read/Write data at 1100H │
└──────────────────────────┘
Example:
If Segment = Code (1000H), Offset = 150H
→ Physical Address = 1000H + 150H = 1150H
If Segment = Data (2000H), Offset = 050H
→ Physical Address = 2000H + 050H = 2050H
6. Stack Memory Within Process
Process Stack Operations
Initial State (SP = 2FFFH):
Address Data
2FFFH ──────────────────
◄──── Stack Top (Empty)
After PUSH 50H:
SP becomes 2FFEH
2FFFH ──────────────────
2FFEH ║ 50H ║ ◄──── New Top
──────────────────
After PUSH 42H:
SP becomes 2FFDH
2FFFH ──────────────────
2FFEH ║ 50H ║
2FFDH ║ 42H ║ ◄──── New Top
──────────────────
After PUSH 30H:
SP becomes 2FFCH
2FFFH ──────────────────
2FFEH ║ 50H ║
2FFDH ║ 42H ║
2FFCH ║ 30H ║ ◄──── New Top
──────────────────
After POP:
Returns 30H, SP becomes 2FFDH
2FFFH ──────────────────
2FFEH ║ 50H ║
2FFDH ║ 42H ║ ◄──── Top
──────────────────
(30H removed)
Key Points:
├─ Stack grows DOWNWARD in memory
├─ SP (Stack Pointer) decreases with PUSH
├─ SP increases with POP
├─ LIFO (Last In First Out) structure
└─ Automatic management by CPU
7. Memory Segmentation vs Paging
┌──────────────────────────────────────────────────────────────┐
│ SEGMENTATION vs PAGING COMPARISON │
├──────────────────────────────────────────────────────────────┤
│ │
│ SEGMENTATION: PAGING: │
│ ├─ Logical Division ├─ Physical Division │
│ ├─ Variable Size ├─ Fixed Size (4 KB) │
│ ├─ Purpose-based ├─ Transparent │
│ │ (Code, Data, Stack) │ │
│ ├─ Programmer visible ├─ Hidden from Programmer │
│ ├─ Can cause fragmentation ├─ No external fragmentation
│ ├─ Matches application logic ├─ Matches physical memory │
│ ├─ 8085 USES THIS ├─ Modern systems use this │
│ └─ Protection/Privilege └─ Virtual memory support │
│ possible possible │
│ │
│ 8085 Memory Organization: Conceptual Paging: │
│ ┌────────────────────────┐ ┌────────────────────────┐
│ │ Code (1000H-1FFFH) │ │ Page 0 (0000H-0FFFH) │
│ ├────────────────────────┤ ├────────────────────────┤
│ │ Data (2000H-2FFFH) │ │ Page 1 (1000H-1FFFH) │
│ ├────────────────────────┤ ├────────────────────────┤
│ │ Stack (2FFFH↓) │ │ Page 2 (2000H-2FFFH) │
│ └────────────────────────┘ ├────────────────────────┤
│ │ ... │
│ └────────────────────────┘
└──────────────────────────────────────────────────────────────┘
8. Multi-Process Memory Organization
System Memory - 64 KB
┌─────────────────────────────────────────────────────┐
│ SYSTEM RESERVED AREA │
│ 0000H - 00FFH (256 bytes) │
│ [Interrupts, System Programs - READ ONLY] │
├─────────────────────────────────────────────────────┤
│ MONITOR / OS │
│ 0100H - 0FFFH (3,840 bytes) │
│ [Operating System Code] │
├─────────────────────────────────────────────────────┤
│ PROCESS 1 MEMORY SPACE │
│ 1000H - 2500H │
│ ├─ Code: 1000H - 1500H (Code instructions) │
│ ├─ Data: 1500H - 2000H (Global variables) │
│ └─ Stack: 2500H - 2000H (Grows downward) │
├─────────────────────────────────────────────────────┤
│ PROCESS 2 MEMORY SPACE │
│ 3000H - 4500H │
│ ├─ Code: 3000H - 3500H (Code instructions) │
│ ├─ Data: 3500H - 4000H (Global variables) │
│ └─ Stack: 4500H - 4000H (Grows downward) │
├─────────────────────────────────────────────────────┤
│ SHARED MEMORY (Available to All Processes) │
│ 5000H - FFFFH (45 KB) │
│ ├─ Shared Data │
│ ├─ Common Routines │
│ └─ System Resources │
└─────────────────────────────────────────────────────┘
Advantages:
├─ Each process has independent code/data/stack
├─ Isolation prevents cross-process interference
├─ Shared memory for communication
├─ Efficient memory usage
└─ Process isolation and protection
9. Process Descriptor and Context
Process Control Block (PCB)
┌────────────────────────────────────────────────┐
│ PROCESS CONTROL BLOCK │
├────────────────────────────────────────────────┤
│ │
│ PROCESS IDENTIFICATION: │
│ ├─ PID (Process ID): 1 │
│ ├─ Process Name: PROC_A │
│ └─ Priority: 5 │
│ │
│ MEMORY POINTERS: │
│ ├─ Code Segment Start: 1000H │
│ ├─ Code Segment End: 1500H │
│ ├─ Data Segment Start: 2000H │
│ ├─ Data Segment End: 2100H │
│ ├─ Stack Base: 2FFFH │
│ └─ Stack Pointer (current): 2FFCH │
│ │
│ CPU CONTEXT (Saved Registers): │
│ ├─ Accumulator (A): 0x50 │
│ ├─ B Register: 0x12 │
│ ├─ C Register: 0x34 │
│ ├─ D Register: 0x56 │
│ ├─ E Register: 0x78 │
│ ├─ H Register: 0x9A │
│ ├─ L Register: 0xBC │
│ ├─ Stack Pointer (SP): 2FFCH │
│ ├─ Program Counter (PC): 1234H │
│ └─ Processor Flags: 10000110B │
│ │
│ PROCESS STATUS: │
│ ├─ State: Running │
│ ├─ Created At: Time T │
│ ├─ Last Executed: Time T+100ms │
│ └─ CPU Time Used: 250ms │
│ │
└────────────────────────────────────────────────┘
Purpose:
├─ Store complete process state
├─ Enable context switching
├─ Track resource allocation
└─ Support process scheduling
10. Virtual to Physical Memory Mapping
Virtual Address Space → Physical Memory
Process View (Virtual): Actual RAM (Physical):
┌──────────────────────────┐ ┌──────────────────────────┐
│ Virtual: 2050H │ │ Physical: 2050H │
│ [PAGE 2 + Offset 050H] │───▶│ [Data in RAM] │
│ │ │ │
│ Virtual: 3100H │ │ Physical: 5100H │
│ [PAGE 3 + Offset 100H] │───▶│ [On Disk or Swapped] │
│ │ │ │
│ Virtual: 1500H │ │ Physical: 1500H │
│ [PAGE 1 + Offset 500H] │───▶│ [Code in RAM] │
│ │ │ │
│ Virtual: 4200H │ │ Physical: 4200H │
│ [PAGE 4 + Offset 200H] │───▶│ [Data in RAM] │
└──────────────────────────┘ └──────────────────────────┘
▲ PAGE TABLE LOOKUP
│ Maps Virtual ▶ Physical
Virtual Address Format:
┌──────────────┬─────────────┐
│ Page Number │ Offset │
│ (4-12 bits) │ (0-11 bits) │
└──────────────┴─────────────┘
│ │
▼ ▼
Page Table Add to Base
Lookup Address
│ │
└──────┬───────┘
▼
Physical Address
Example: Virtual 2050H
├─ Page Number: 2 (Page 2)
├─ Offset: 050H
├─ Page Table[2] = 2000H (Base)
├─ Physical = 2000H + 050H = 2050H
└─ Access Memory[2050H]
11. Segmentation Details
Segment-Based Address Translation
┌─────────────────────────────────────────────┐
│ SEGMENT DESCRIPTOR TABLE │
├─────────────────────────────────────────────┤
│ │
│ Segment 0 (System): │
│ ├─ Base Address: 0000H │
│ ├─ Segment Size: 100H (256 bytes) │
│ ├─ Permissions: Read-Only │
│ └─ Type: System / Interrupts │
│ │
│ Segment 1 (Code): │
│ ├─ Base Address: 1000H │
│ ├─ Segment Size: 1000H (4 KB) │
│ ├─ Permissions: Read/Execute │
│ └─ Type: Program Code │
│ │
│ Segment 2 (Data): │
│ ├─ Base Address: 2000H │
│ ├─ Segment Size: 1000H (4 KB) │
│ ├─ Permissions: Read/Write │
│ └─ Type: Variables / Constants │
│ │
│ Segment 3 (Stack): │
│ ├─ Base Address: 2FFFH (Top) │
│ ├─ Segment Size: 1000H (4 KB) │
│ ├─ Permissions: Read/Write │
│ └─ Type: Stack / Temporary │
│ │
└─────────────────────────────────────────────┘
Address Translation Process:
┌─ Logical Address ────────────┐
│ ┌──────────────────────────┐│
│ │ Segment: 2 (Data) ││
│ │ Offset: 0050H ││
│ └──────────────────────────┘│
└────────────────┬─────────────┘
│
▼
┌────────────────────────┐
│ Look up Segment 2 │
│ in Descriptor Table │
└────────────┬───────────┘
│
▼
┌────────────────────────┐
│ Get Base Address: │
│ Segment 2 = 2000H │
└────────────┬───────────┘
│
▼
┌────────────────────────┐
│ Add Offset to Base: │
│ 2000H + 0050H = 2050H │
└────────────┬───────────┘
│
▼
┌────────────────────────┐
│ Physical Address: │
│ 2050H │
└────────────────────────┘
12. Complete Process Lifecycle with Memory
Complete Process Lifecycle
┌─────────────────────────────────────────────────┐
│ STAGE 1: PROCESS CREATION │
│ ├─ Allocate memory: │
│ │ • Code Segment: 1000H - 1500H (1.25 KB) │
│ │ • Data Segment: 2000H - 2100H (256 B) │
│ │ • Stack Segment: 2FFFH downward │
│ │ │
│ ├─ Initialize Registers: │
│ │ • SP (Stack Pointer) = 2FFFH │
│ │ • PC (Program Counter) = 1000H │
│ │ • A, B, C, D, E, H, L = 0 │
│ │ │
│ └─ Create Process Control Block (PCB) │
│ • Assign PID │
│ • Set Status = NEW │
│ • Initialize all fields │
└────────┬────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────┐
│ STAGE 2: READY QUEUE │
│ ├─ Add to Ready Queue │
│ ├─ Status = READY │
│ └─ Waiting for CPU scheduler to assign time │
└────────┬────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────┐
│ STAGE 3: EXECUTION │
│ ├─ CPU Scheduler selects process │
│ ├─ Load context (registers, SP, PC) from PCB │
│ ├─ Status = RUNNING │
│ │ │
│ ├─ Execute instructions from Code Segment │
│ │ • Fetch from PC │
│ │ • Execute │
│ │ • Increment PC │
│ │ • Access Data Segment as needed │
│ │ • Use Stack for function calls │
│ │ │
│ └─ Continue execution... │
└────────┬────────────────────────────────────────┘
│
├─────────────┬──────────────┐
│ │ │
▼ ▼ ▼
┌────────┐ ┌─────────┐ ┌──────────┐
│I/O REQ │ │INTERRUPT│ │TIME SLICE│
│? │ │? │ │EXPIRED? │
└────┬───┘ └────┬────┘ └────┬─────┘
│YES │YES │YES
│ │ │
▼ ▼ ▼
┌──────────────────────────────────────────┐
│ CONTEXT SAVE (Stage 4) │
├──────────────────────────────────────────┤
│ Save to PCB: │
│ • All Registers (A, B, C, D, E, H, L) │
│ • Stack Pointer (SP) │
│ • Program Counter (PC) │
│ • Processor Flags │
│ • Process State │
│ │
│ Status = WAITING or READY │
└────────┬─────────────────────────────────┘
│
▼
┌──────────────────────────────────┐
│ SWITCH CONTEXT (Stage 5) │
│ Load next process's context │
│ Back to STAGE 3 for next process │
└──────────────────────────────────┘
Or continuing:
│NO │NO
▼ ▼
┌──────────────────────────────────┐
│ CONTINUE EXECUTION (Stage 3) │
│ Keep running... │
└──────────────────────────────────┘
Eventually:
┌─────────────────────────────────────────────────┐
│ STAGE 5: COMPLETION │
│ ├─ Program reaches HLT instruction │
│ ├─ Or process calls EXIT │
│ ├─ Or error occurs │
│ │ │
│ ├─ Deallocate Memory: │
│ │ • Free Code Segment │
│ │ • Free Data Segment │
│ │ • Free Stack Segment │
│ │ │
│ ├─ Return resources to system │
│ ├─ Delete Process Control Block (PCB) │
│ ├─ Remove from all queues │
│ │ │
│ └─ Status = TERMINATED │
└─────────────────────────────────────────────────┘
13. Stack Operations Within Process Context
Function Call Stack Operations
Initial State:
PC = 1000H (start of main program)
SP = 2FFFH
┌────────────────┐
│ Main Program │
│ 1000H: │
│ ... │
│ CALL SUBR │◄─── Jump to subroutine
│ 1010H │
│ ... │
└────────────────┘
Step 1: CALL SUBR - Push Return Address
┌─────────────────┐
│ SP = 2FFFH │ Before: Stack empty
│ (decrements to │
│ 2FFEH) │
│ │
│ 2FFEH: [1010H] │ Address 1010H stored
│ ◄─ Return addr │ (location after CALL)
└─────────────────┘
PC = 1100H (subroutine address)
Step 2: Inside Subroutine - Save Registers
Subroutine code:
1100H: PUSH B
PUSH D
...
┌─────────────────┐
│ SP = 2FFEH │ [1010H] Return address
│ (decrements to │
│ 2FFDH) │
│ │
│ 2FFDH: [BB] │ B register saved
│ 2FFCH: [DD] │ D register saved
│ ◄─ Current SP │
└─────────────────┘
Step 3: Subroutine Operations
- Use registers
- Call other subroutines
- Access data
Step 4: Return - Restore Registers
Subroutine code:
1125H: POP D
POP B
RET
┌─────────────────┐
│ After POP D: │
│ SP = 2FFDH │ [1010H] Return address
│ D restored │ [BB] Still for B
│ │
│ After POP B: │
│ SP = 2FFEH │ [1010H] Return address
│ B restored │ ◄─ Current SP
│ │
│ RET: │
│ SP = 2FFFH │ Stack empty
│ PC = 1010H │ Back to main!
│ ◄─ Continue │
└─────────────────┘
Key Point:
├─ CALL pushes return address
├─ PUSH saves registers
├─ POP restores registers
├─ RET pops return address back to PC
└─ Stack manages entire context automatically
14. Memory Fragmentation in Multi-Process System
Memory Fragmentation Over Time
Initial State: All Memory Free
┌─────────────────────────────────────────────────┐
│ [FREE: 64 KB - All Available] │
├─────────────────────────────────────────────────┤
│ 0000H FFFFH│
└─────────────────────────────────────────────────┘
After Process 1 Created (4 KB):
┌─────────────────────────────────────────────────┐
│ [PROC1: 4KB] [FREE: 60KB] │
├─────────────────────────────────────────────────┤
│ 0000H 1000H FFFFH│
└─────────────────────────────────────────────────┘
After Process 2 Created (3 KB):
┌─────────────────────────────────────────────────┐
│ [PROC1: 4KB] [PROC2: 3KB] [FREE: 57KB] │
├─────────────────────────────────────────────────┤
│ 0000H 1000H 2000H FFFFH│
└─────────────────────────────────────────────────┘
After Process 1 Terminates:
┌─────────────────────────────────────────────────┐
│ [FREE: 4KB] [PROC2: 3KB] [FREE: 57KB] │
├─────────────────────────────────────────────────┤
│ 0000H 1000H 2000H FFFFH│
└─────────────────────────────────────────────────┘
FRAGMENTATION OCCURS:
- Gap at 0000H-1000H (4 KB) - unusable
- Gap at 2000H-FFFFH (57 KB) - free but fragmented
- Process 3 needs 5 KB contiguous memory
- Cannot fit! (4 KB gap too small, 57 KB gap fragmented)
After Process 2 Terminates:
┌─────────────────────────────────────────────────┐
│ [FREE: 4KB] [FREE: 3KB] [FREE: 57KB] │
├─────────────────────────────────────────────────┤
│ 0000H 1000H 2000H FFFFH│
└─────────────────────────────────────────────────┘
Total Free: 64 KB, but no single 5 KB contiguous block!
SOLUTION: Memory Compaction
┌─────────────────────────────────────────────────┐
│ [FREE: 64KB - Compacted] │
├─────────────────────────────────────────────────┤
│ 0000H FFFFH│
└─────────────────────────────────────────────────┘
After Compaction:
- All free space consolidated
- Contiguous memory available
- Process 3 (5 KB) can now be allocated
- No fragmentation
Fragmentation Types:
├─ External Fragmentation:
│ └─ Free blocks scattered in memory
│ Cannot satisfy request despite total free space
│
└─ Internal Fragmentation:
└─ Allocated block larger than needed
Unused portion within block
15. Complete 8085 Memory Segmentation Model
8085 Microprocessor
Memory System (64 KB)
Address Space: 0000H - FFFFH
┌─────────────────────────────────────────────────────┐
│ SEGMENT 1: SYSTEM RESERVED AREA │
├─────────────────────────────────────────────────────┤
│ Range: 0000H - 00FFH │
│ Size: 256 bytes │
│ Purpose: Interrupt vectors, system programs │
│ Characteristics: │
│ ├─ Read-Only (typically) │
│ ├─ DO NOT WRITE to this area │
│ ├─ Critical system data │
│ └─ Managed by OS/System │
└─────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────┐
│ SEGMENT 2: RESERVED AREA │
├─────────────────────────────────────────────────────┤
│ Range: 0100H - 0FFFH │
│ Size: 3,840 bytes (3.75 KB) │
│ Purpose: OS/Monitor programs, utilities │
│ Characteristics: │
│ ├─ Usually protected │
│ ├─ OS/Monitor code │
│ ├─ May be ROM or protected RAM │
│ └─ System-managed only │
└─────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────┐
│ SEGMENT 3: CODE SEGMENT (Program Area) │
├─────────────────────────────────────────────────────┤
│ Range: 1000H - 1FFFH │
│ Size: 4,096 bytes (4 KB) │
│ Purpose: Executable program instructions │
│ Characteristics: │
│ ├─ Contains machine code │
│ ├─ Should be read-only (ideally ROM) │
│ ├─ Execution starts here (PC initialized to 1000H) │
│ ├─ Subroutines located here │
│ ├─ DO NOT MODIFY during execution │
│ └─ Program Counter (PC) points here │
│ │
│ Program flow: │
│ ├─ CPU fetches instruction from PC │
│ ├─ Executes instruction │
│ ├─ PC increments │
│ └─ Repeat │
└─────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────┐
│ SEGMENT 4: DATA SEGMENT (Variables/Constants) │
├─────────────────────────────────────────────────────┤
│ Range: 2000H - 2FFFH │
│ Size: 4,096 bytes (4 KB) │
│ Purpose: Global variables, constants, tables │
│ Characteristics: │
│ ├─ Read/Write access │
│ ├─ Stores program data │
│ ├─ Constants and look-up tables │
│ ├─ Global variable initialization │
│ ├─ Static data allocation │
│ └─ Survives program execution │
│ │
│ Typical Contents: │
│ ├─ Look-up tables │
│ ├─ Constants and configuration │
│ ├─ Global variable values │
│ └─ Status flags and counters │
└─────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────┐
│ SEGMENT 5: STACK SEGMENT (Temporary Storage) │
├─────────────────────────────────────────────────────┤
│ Range: 2FFFH downward (toward 2000H) │
│ Size: 1-4 KB (depends on usage) │
│ Purpose: Temporary storage, function calls │
│ Characteristics: │
│ ├─ LIFO (Last In First Out) structure │
│ ├─ Grows downward in memory │
│ ├─ Automatic management by CPU │
│ ├─ SP (Stack Pointer) manages position │
│ ├─ Used by PUSH/POP instructions │
│ ├─ Function return addresses │
│ ├─ Saved registers during context switch │
│ └─ Local variables in high-level languages │
│ │
│ Stack Management: │
│ ├─ PUSH: SP decreases, data stored │
│ ├─ POP: data retrieved, SP increases │
│ ├─ CALL: pushes return address │
│ ├─ RET: pops return address to PC │
│ └─ Automatic during interrupts │
└─────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────┐
│ SEGMENT 6: UPPER MEMORY / EXTENDED AREA │
├─────────────────────────────────────────────────────┤
│ Range: 3000H - FFFFH │
│ Size: 52,224 bytes (52 KB) │
│ Purpose: Extended user programs, ROM, I/O │
│ Characteristics: │
│ ├─ Large capacity │
│ ├─ User application area │
│ ├─ May contain ROM (firmware, monitor) │
│ ├─ I/O mapped memory │
│ ├─ Device drivers │
│ ├─ Extended data storage │
│ └─ Multiuser/multitask application space │
│ │
│ Typical Usage: │
│ ├─ Large programs that don't fit in Code segment │
│ ├─ Extended data for large applications │
│ ├─ Shared program libraries │
│ ├─ System buffers │
│ ├─ I/O device registers │
│ └─ Additional ROM areas │
└─────────────────────────────────────────────────────┘
Total Memory Organization:
┌────────────────────────────────┐
│ FFFFH │ ▲
├────────────────────────────────┤ │
│ Extended Area (52 KB) │ │
│ 3000H - FFFFH │ │
├────────────────────────────────┤ │
│ Stack (grows ↓) │ │ 64 KB Total
│ 2FFFH - 2000H │ │
├────────────────────────────────┤ │
│ Data Segment (4 KB) │ │
│ 2000H - 1FFFH │ │
├────────────────────────────────┤ │
│ Code Segment (4 KB) │ │
│ 1000H - 0FFFH │ │
├────────────────────────────────┤ │
│ Reserved (3.75 KB) │ │
│ 0100H - 0FFFH │ │
├────────────────────────────────┤ │
│ System Area (256 B) │ │
│ 0000H - 00FFH │ ▼
└────────────────────────────────┘
16. Process Memory Access Patterns
Process Memory Access Patterns
┌────────────────────────────────────────────────┐
│ ACCESS PATTERN 1: SEQUENTIAL EXECUTION │
├────────────────────────────────────────────────┤
│ │
│ Code Segment Access: │
│ │
│ 1000H: MVI A, 50H ◄─ Fetch, Execute │
│ 1002H: MOV B, A ◄─ Fetch, Execute │
│ 1003H: LDA 2000H ◄─ Fetch, Execute │
│ 1006H: STA 2001H ◄─ Fetch, Execute │
│ ... ◄─ Continue │
│ │
│ PC increments sequentially: 1000 → 1002 → 1003│
│ → 1006 → ... │
│ │
└────────────────────────────────────────────────┘
┌────────────────────────────────────────────────┐
│ ACCESS PATTERN 2: UNCONDITIONAL JUMP │
├────────────────────────────────────────────────┤
│ │
│ 1000H: MVI A, 50H │
│ 1002H: JMP 1100H ◄─ Jump to 1100H │
│ ... │
│ 1100H: MOV B, A ◄─ Continue here │
│ 1101H: ... │
│ │
│ PC changes non-sequentially: 1002 → 1100 │
│ │
└────────────────────────────────────────────────┘
┌────────────────────────────────────────────────┐
│ ACCESS PATTERN 3: CONDITIONAL JUMP │
├────────────────────────────────────────────────┤
│ │
│ 1000H: CMP B ◄─ Compare │
│ 1001H: JZ 1050H ◄─ Jump if Zero │
│ (depends on result) │
│ 1003H: MOV A, 30H ◄─ Execute if not Z │
│ ... │
│ 1050H: MOV A, 00H ◄─ Execute if Z │
│ │
│ PC depends on flags: either 1003 or 1050 │
│ │
└────────────────────────────────────────────────┘
┌────────────────────────────────────────────────┐
│ ACCESS PATTERN 4: SUBROUTINE CALL │
├────────────────────────────────────────────────┤
│ │
│ 1000H: CALL 1200H ◄─ Call subroutine │
│ 1002H: MOV B, A ◄─ After return │
│ ... │
│ 1200H: (Subroutine) │
│ 1200H: MOV A, 50H ◄─ Execute subroutine│
│ 1202H: RET ◄─ Return to 1002 │
│ │
│ Flow: 1000→1002→(call)→1200→1202→1002→... │
│ Stack holds return address 1002 during call │
│ │
└────────────────────────────────────────────────┘
┌────────────────────────────────────────────────┐
│ ACCESS PATTERN 5: DATA SEGMENT ACCESS │
├────────────────────────────────────────────────┤
│ │
│ Load from Data Segment: │
│ 1010H: LDA 2000H ◄─ Load variable │
│ 1013H: ADD A, B ◄─ Process │
│ 1014H: STA 2001H ◄─ Store variable │
│ │
│ Code: 1010→1013→1014 │
│ Data: Access 2000H, 2001H │
│ │
└────────────────────────────────────────────────┘
┌────────────────────────────────────────────────┐
│ ACCESS PATTERN 6: STACK USAGE │
├────────────────────────────────────────────────┤
│ │
│ 1050H: PUSH B ◄─ Save register │
│ 1051H: PUSH D ◄─ Save register │
│ 1052H: MOV A, 50H ◄─ Use for work │
│ 1054H: POP D ◄─ Restore register │
│ 1055H: POP B ◄─ Restore register │
│ │
│ Code: 1050→1051→1052→1054→1055 │
│ Stack: 2FFFH→2FFEH→2FFDH→2FFEH→2FFFH │
│ │
│ Data preserved on stack, restored after use │
│ │
└────────────────────────────────────────────────┘
Summary of Memory Access:
├─ Code Segment (1000H-1FFFH):
│ └─ Sequential with jumps/calls
├─ Data Segment (2000H-2FFFH):
│ └─ Random access, read/write
└─ Stack (2FFFH↓):
└─ LIFO, automatic management
Summary and Key Concepts
Memory Organization Principles
- Segmentation: Logical division of memory by purpose
- Paging: Fixed-size pages for management
- Process Isolation: Each process has independent segments
- Stack Management: Automatic LIFO management by CPU
- Memory Protection: Prevent unauthorized access
- Context Switching: Save/restore process state
Process Management
- Each process has its own code, data, and stack
- Process Control Blocks maintain process state
- CPU scheduler manages process execution
- Context switching saves/restores registers
- Memory fragmentation requires management
Memory Efficiency
- Use segmentation for logical organization
- Minimize external fragmentation
- Compact memory when needed
- Share common code segments
- Efficient stack usage for function calls
8085 Specific
- 64 KB total addressable memory
- 16-bit address space (0000H - FFFFH)
- Stack grows downward
- Program execution starts at 1000H (typically)
Fixed segment sizes:
- System: 256 bytes
- Code: 4 KB
- Data: 4 KB
- Stack: 1-4 KB
- Extended: 52 KB