CSCE 312 Spring 2022
Computer Organization
Homework 6

Cache Simulator

Due at 11:59pm, April 28, 2022.

Write a cache simulator. Write your program in C or C++ and call it cache.c (for C) or cache.cc (for C++). The program should work by the following specifications:

Command-Line Parameters

There should be four command line parameters in this order:
  1. nk: the capacity of the cache in kilobytes (an int)
  2. assoc: the associativity of the cache (an int)
  3. blocksize: the size of a single cache block in bytes (an int)
  4. repl: the replacement policy (a char); 'l' means LRU, 'r' means random.

Input

Read traces from the standard input. Each line on the standard input will be a lowercase 'r' (for read) or 'w' (for write) followed by a space and then a 64-bit hexadecimal number giving the address of the memory access. For example, a snippet of a trace file looks like this:
r 56ecd8
r 47f639
r 7ff0001ff
w 47f63e
r 4817ef
r 7d5ab8

Output

The output should be a single line of six numbers separated by spaces. These six numbers are:
  1. The total number of misses,
  2. The percentage of misses (i.e. total misses divided by total accesses),
  3. The total number of read misses,
  4. The percentage of read misses (i.e. total read misses divided by total read accesses),
  5. The total number of write misses,
  6. The percentage of write misses (i.e. total write misses divided by total write accesses).

What to turn in

Turn in your assignment as a C++ file through Canvas. Make your program a single file.

For a successful assignment

Write this code yourself. Do not receive assistance from anyone except for your professor.

Late assignments will not be accepted.