KembaraXtra-Computer Science - Main Memory
1. Purpose of Main Memory
• Stores program instructions and data needed for execution.
• Example: Word processor program, document content, editing state.
• Stores data as bits (1s and 0s) that the CPU can access.
2. Types of Memory
• SRAM (Static Random Access Memory):
- Uses flip-flops to store bits.
- Static: Retains data as long as power is supplied.
- Faster, more expensive.
- Used in cache memory (where speed is critical).
• DRAM (Dynamic Random Access Memory):
- Uses a transistor and capacitor to store bits.
- Dynamic: Capacitor charge leaks, so data must be periodically refreshed (rewritten).
- Slower, less expensive.
- Commonly used for main memory.
3. Memory Organization
• Internally organized as grids of memory cells (each storing 1 bit).
• Cells are accessed using two-dimensional coordinates.
• Multiple grids are accessed in parallel to read/write multiple bits at once (e.g., a byte).
4. Memory Addresses
• Memory Address: A numeric value that identifies a specific location in memory.
• Byte-Addressable: Each memory address refers to 8 bits (1 byte) of data.
5. Example: 64KB Memory System
• Memory Size: 64KB (64 x 1024 = 65,536 bytes).
• Address Range: 0 to 65,535 (0x0000 to 0xFFFF in hexadecimal).
• Address Representation: Binary numbers.
• Calculating Bits Required for Addressing:
- 2^n = number of unique addresses
- n = log₂(number of unique addresses)
- For 65,536 bytes: log₂(65,536) = 16 bits.
- Alternatively: 0xFFFF (hex) = 4 hex characters × 4 bits/character = 16 bits.
• Significance of Number of Bits: Limits the maximum amount of memory the computer can access.
6. Memory Layout Example
• Memory addresses (in binary or hex) are associated with data bytes.
• Example: Storing the ASCII string "Hello" starting at address 0x0002:
Memory Address Data Byte (Hex) Data as ASCII
0000 00
0001 00
0002 48 H
0003 65 e
0004 6C l
0005 6C l
0006 6F o
0007 00 (Null Term.)
• Null Terminator: Some languages use a null terminator (byte equal to 0) to mark the end of a string.
7. Memory Inspection Tools
• Display memory contents in hexadecimal format.
• Show a memory address followed by 16 bytes of data at that address and the subsequent 15 addresses.
8. Modern Memory Sizes
• Modern devices have much larger memories (GBs).
• Example: Smartphones (1GB+), Laptops (4GB+).
9. Practice: Calculating Bits for 4GB Memory
• 4GB = 4 × 2³⁰ bytes = 2² × 2³⁰ = 2³² bytes
• log₂(2³²) = 32 bits required to address 4GB of memory.