3.10 Cache Simulator

In C, write a program that simulates a cache and displays whether address references are hits or misses.

Your program should expect any number of simulations on standard input. Each simulation starts with a single line with four numbers on it: the number of addresses, the number of sets, the number of lines per set, and then the size of lines (in addresses). Each simulation then consists of any number of addresses (numbers smaller than the number of addresses) delimited by newline characters (\n) on standard input and display the message Hit! :D\n or Miss! :P\n on standard output for each address. A simulation ends with the input q. After a simulation ends, if the input to the program ends, then the program should exit without errors.

The program should have no other output.

Since this is an extra-credit assignment, there are four options, each with a different amount of extra credit. First, you can implement the assignment so the cache parameters are fixed and cannot be changed by the input (although still require it to be there!). Second, you can implement the cache so that you do not support set-associativity, but support arbitrary parameters. Third, if you do support set-associativity, you don’t have to implement LRU replacement, but can implement any convenient policy. Finally, you can implement set-associativity and LRU replacement. Each extension will be equal in weight.

You must turn in
  • A README file that contains a short write-up of your project. It should discuss the approach you took to solving the problem, it should discuss any problems or issues that still remain, it should discuss any interesting things that you learned in the course of the project. Finally, it should provide the grade you believe the project deserves with a detailed explanation of why. This explanation should almost certainly focus on why you believe the program is correct.

    This file must be in plain-text. If you need formatting, use Markdown. It must be limited to 80 characters wide, unless you are quoting program output.

  • Your source code, named e1.c.

  • A test input file, named test.in, that contains example input. However, there are examples in the chapter six slide set, if you would like to use them.

  • A test output file, named test.out, that contains the expected output for the test data.

  • A Makefile that first builds the program and then tests it by running it with test.in as the input and compares the actual output to test.out.

This assignment will be graded based on its correctness and your ability to articulate why it is correct.