Suppose in a system we store data using arrays, we have $2$ arrays A and B. Array A contains $256$ elements of size $4$ bytes each. The first element is stored at physical address $4096$. Another array B contains $512$ elements of size $4$ bytes each, stored from physical address location $8192$.

Assume that only arrays A and B can be cached in an initially empty, physically addressed, physically tagged, direct mapped cache whose size is $2$ KB with $8$ byte block size. Now we run below loop in the system:

for( p=0; p<256; p++)
{
A[p] = A[p] + B[2*p]
}

If the cache use write back policy, the number of bytes that will be written to memory during execution of the loop is :

- $256$
- $1$
- $0$
- $2048$

**Doubt: **

Cache has 256 blocks, Array A has 128 blocks, Array B has 256 blocks. For the given loop, we are accessing every block of A and B exactly once, now as all blocks of A + B cannot be stored in the cache, exactly 128 blocks of B will need replacement, and hence there will be write-back in memory.

__The answer is given as 0__ but I think it’s wrong,because if the loop statement was

A[p] = A[p] + B[p]

then the answer would be 0, as then 128 blocks of A and 128 blocks of B would be accessed which would fit exactly in our 256 block cache.