I study cache memories. I'm supposed to calculate the data hit rate for a function call with a 1024 byte direct mapped data cache and block size 16 byte.
sum(0x55aa1000,10);
The function is in MIPS 32 assembly
sum:
xor $v0, $v0, $v0
loop:
lb $t0, 0($a0)
add $v0, $v0, $t0
addi $a0, $a0, 1
addi $a1, $a1, -1
bne $a1, $zero, loop
jr $ra
My attempt at solution:
The set field is 7 bits because 1024/16=128=2^7 and the byte offset field is 4 bits because the block size is 16. Therefore the tag field is 32-7-4=21 bits. The tags are the same for all data accesses(?)
Since the loop increments data offset by 1 byte and decrements the counter by 1, it will be run 10 times, the first time will be a miss and the rest will be a hit because it is within the same block.
Therefore the hit rate will be 90 %.
Is my solution correct?