Nios/cachetag

From ASMBits

Consider the following cache:

  • Capacity of C bytes
  • Associativity of W ways

Write a function that will determine whether the cache blocks holding two addresses will have the same tag, for the above cache. Your function will be provided C, W, and two addresses. It must return 1 or 0 to indicate whether the cache blocks holding the two addresses would have the same tag field. C and W will be valid values for a 32-bit address, and will correspond to a cache where the block size and number of sets are powers of two.

int cachetag(unsigned int C, unsigned int W, unsigned int addr1, unsigned int addr2);

Expected solution length: Around 10 lines.

Sample Input

cachetag(12288, 3, 0, 2) (12 KB, 3-way)

Sample Output

r2=1

Write your solution here

Upload a source file...