Simulates a direct-mapped, write-back cache with a 16-slot configuration.
- 2 KB main memory initialized with sample values
- 16 cache slots, each storing a 16-byte block
- Supports read, write, and display operations
- Calculates offset, slot number, and tag for each address
- Displays cache contents in hex
- Clone the repository
git clone https://github.com/christalphilip/cache-simulator.git cd cache-simulator
- Compile the Java file
javac CacheSimulator.java
Run the program:
java CacheSimulator
Choose from:
- (R) Read from an address (hex input)
- (W) Write to an address (hex input + data)
- (D) Display the current cache
(R)ead, (W)rite, or (D)isplay Cache? R What address would you like read? 5 At that byte there is the value 05 (Cache Hit)
(R)ead, (W)rite, or (D)isplay Cache? W What address would you like to write to? 14C What data would you like to write at that address? 99 Value 99 has been written to address 14C. (Cache Hit) ...
cache-simulator/ ├── CacheSimulator.java ├── README.md ├── LICENSE ├── .gitignore └── output.txt
This project is licensed under the MIT License.