'how many number of Cache misses can occur in given c code

Suppose we have two 2-dimensional arrays m and n, and consider the following C code.

int m[4][4];

int n[4][4];



for (int i = 0; i < 4; i++)

   for (int j = 0; j < 4; j++)

   {

         m[i][j] = 0;

         n[j][i] = 1;

    }
 

Assume that array m starts at address 0 and array n starts at address 64; the size of int is 4 bytes; the cache is 32 bytes and direct-mapped with a block size of 16 bytes; the cache is initially empty; accesses to the m and n arrays are the only sources of misses.

(a) Out of 16 accesses to array m, how many are cache misses?

(b) Out of 16 accesses to array n, how many are cache misses?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source