You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This assignment reflects a comprehensive development effort. Collaboration with my roommate, Burak YalΓ§Δ±n (Student ID: 20220808069), was crucial.
Our discussions refined our understanding of:
Addressing Modes
Program Counter (PC) Increment Logic
Cache Interaction
π Project Structure
File
Description
Memory.java
Simulates 64 KB main memory with byte-level read/write operations.
Cache.java
Implements a direct-mapped cache with 16 bytes (8 blocks, 2 bytes each).
CPUEmulator.java
Manages CPU logic, including fetch-decode-execute cycle.
Main.java
Application entry point; loads and executes the program.
π System Specifications & Implementation Details
π§ CPU Registers
Register
Description
Program Counter (PC)
Stores the next instruction address.
Accumulator (AC)
16-bit register for arithmetic/logical operations.
Comparison Flag
Set to -1, 0, or 1 by comparison instructions.
π Main Memory
Specification
Details
Capacity
65,536 bytes (64 KB)
Addressability
Byte-addressable
Endianness
Little-endian (16-bit values)
π Instruction Format
Property
Details
Size
16-bit
Structure
4-bit opcode + 12-bit operand
Storage
Each instruction occupies 2 bytes
π Program Loading
Loaded into main memory starting at the loadAddress from config.txt.
Each 16-bit instruction occupies 2 consecutive bytes.
π Addressing Modes
Mode
Description
Immediate
Operand contains the direct value (for LOAD, ADD, SUB, MUL).
Relative
Effective address is loadAddress + operand.
Absolute
(For PC/Jumps) loadAddress + operand * 2.
π Cache Implementation Details
Property
Value
Cache Size
16 bytes
Block Size
2 bytes
Number of Blocks
8 (16 bytes / 2 bytes/block)
Mapping
Direct-Mapped
β Policies
Policy
Description
Write-Through
Writes immediately update main memory.
Write-Allocate
On write miss, block fetched from memory before writing.
π Address Breakdown
Field
Size
Purpose
Offset
1 bit
Selects the byte within a 2-byte block.
Index
3 bits
Selects one of 8 cache blocks.
Tag
12 bits
Verifies cache hit.
β‘ Cache Accesses
All data memory operations (LOADM, STOREM, etc.) pass through the cache.
Instruction fetches also utilize the cache, contributing to access stats.
π§ Development Challenges & Resolution
β‘ Addressing Mode Ambiguity
Issue
Solution
Interpreting "Absolute (for PC/Jumps)"
Treated jump operands as relative instruction indices.
π PC Increment and Fetch Logic
Standard Behavior
Adjusted Behavior
PC += 2 after each instruction
Fetches counted as cache accesses for hit/miss stats.
β Final Implementation Approach
Program Loading: Directly into the Memory object.
Instruction Fetching: Via cache, affecting hit/miss ratio.
PC Management: Increments by 2, except for jumps.
Jump Calculation:loadAddress + operand * 2.
Memory Operations: Accessed through cache.
π§ Debugging and Notes
Extensive use of System.out.println for tracing execution.
Memory operand instructions (LOADM, STOREM, etc.) operate on single bytes.
Little-endian byte ordering for 16-bit instructions.
Named constants (e.g., VALID, TAG in Cache.java) for clarity.