a
is already stored in
register s2
, the variable i
is already stored in
register s1
, and the variable size
is already stored
in register s3
.
for(i = 0; i < size; i++) { a[i] = i + 5; } i = 0;
move $v0, $zero # initialize v0 to 0 move $t0, $zero # initialize t0 to 0 Loop: beq $t0, $s0, Exit # if t0 == s0, go to Exit sll $t1, $t0, 2 # t1 = t0 * 4 add $t1, $t1, $s2 # t1 = s2 + (t0 * 4) lw $t2, 0($t1) # bring element in from memory add $v0, $v0, $t2 # v0 += t2 sw $t2, 0($t1) # send updated value back to memory addi $t0, $t0, 1 # increment t0 j Loop Exit:
1000 1101 0010 1000 0000 0100 1011 0000
The cache row address and tag for this cache will be calculated as follows:
31 ... 6|5 ... 2|1 0 -------------------- | Tag | Row |0 0| instruction address -------------------- /|\ | ignore these bits (byte offset)The instructions being executed are:
Address Instruction ======= ============================ 4000d Loop: beq $s0, $zero, Exit # immediate = 6, offset to Exit 4004d add $t0, $s0, $s2 # compute read address 4008d add $t1, $s0, $s3 # compute write address 4012d lw $t2, 0($t0) # read data 4016d sw $t2, 0($t1) # write data 4020d sub $s0, $s0, $s1 # subtract offset 4024d j Loop # immediate = 1000 which is 4000/4 4028d Exit:Fill in the following cache table and state how many cache misses this design has. Assume that the code starts executing at the Loop: tag, that is executes for EXACTLY two interations, and that the cache is empty at the start.
Row (4 bits) | Valid? | Tag (26 bits) | Data (1 instruction) |
---|---|---|---|
0000 (0) | |||
0001 (1) | |||
0010 (2) | |||
0011 (3) | |||
0100 (4) | |||
0101 (5) | |||
0110 (6) | |||
0111 (7) | |||
1000 (8) | |||
1001 (9) | |||
1010 (10) | |||
1011 (11) | |||
1100 (12) | |||
1101 (13) | |||
1110 (14) | |||
1111 (15) |