Nios/cachehits2

From ASMBits

Consider the following cache:

  • Direct-mapped (i.e., 1-way set-associative)
  • 2B block size
  • 2S sets

Your function will be provided B, S, an array of tags (one for each cache block), and a list of addresses. Write a function that will determine the number of cache hits if the sequence of accesses were performed on the cache with the given initial state. After each access, update the cache state (you may modify the tag array).

Assume every cache block in the cache is valid. The array of tags contains exactly 2S words, one for each set. Each entry in the array is a 32-bit word, but only the tag bits are valid (the lower bits that correspond to the set number and offset are undefined). You may modify this array as the cache state is updated.

The address list contains an array of 32-bit addresses, and is terminated with -1. Do not process the -1 as if it were an address.

Your function should return the number of cache hits if the list of cache accesses were performed on the cache.

int cachehits(unsigned int B, unsigned int S, unsigned int *cachetags, unsigned int *addrlist);

Expected solution length: Around 40 lines.

Sample Input

[See below]

Sample Output

r2=2

Write your solution here

Upload a source file...