CS 208: Computer Organization & Architecture

Practice exercises on caches

Nothing to hand in

This exercise is a continuation of the stuff we did with caches during class on Monday, May 27. Nothing to hand in, but you'll likely find it worthwhile to have done this exercise once you get the takehome final.

Goals

Code

We'll be pretending to execute the following subroutine, assuming $a0 = 9. That is, we're running the loop below through 8 iterations.

# The fibonacci subroutine. # Precondition: $a0 contains N # Post-condition: $v0 contains the Nth fibonacci number, where # f_0 = f_1 = 1, f_2 = 2, etc. fib: addiu $v0, $zero, 1 # current fibonacci number addiu $t0, $zero, 1 # previous fibonacci number addiu $t1, $zero, 1 # loop counter fibloop: sltu $t2, $t1, $a0 bnez $t2, fibbody jr $ra fibbody: add $t2, $v0, $t0 move $t0, $v0 move $v0, $t2 addiu $t1, $t1, 1 b fibloop

Assumptions

Scenario #1

Here's our cache:

Using the assumptions listed above, simulate the execution of the fib subroutine, and answer these questions:

Scenario #2

Same questions as Scenario #1, but with this cache:

Scenario #3

Same questions as Scenario #1, but with this cache:

Scenario #4

Same questions as Scenario #1, but with this cache:

Extra questions