Rob
Rob

Reputation: 171

Explanation needed on sample MIPS example

So i have a sample question for an upcoming mips test and needed a clarification.

  1. Suppose word array A stores 0,1,2,3,4,5,6,7,8,9, in this order. Assume the starting address of A is currently in $s0. After the following instructions, what will be the value in $t1?

ori $t0, $0, 6

p7L0: lw $t1, 0($s0)
sll $t1, $t1, 2
blt $t0, $t1, p7L1
addi $s0, $s0, 4 
j p7L0    

p7L1:

(a) 2 (b) 3
(c) 6 (d) None of the above.

In this example the answer comes out to 8. Yet im kind of confused how it got that. In my run through, in the command ori i get 6. It goes to the sll and it comes out with 0. Since 0 is less than 6, it branches to p7L1:

Clarification?

Upvotes: 0

Views: 254

Answers (1)

Paul R
Paul R

Reputation: 212969

The sll instruction multiplies t1 by 4, so its value each time throught the loop will be 0, 4, 8, and then the branch will be taken, because 6 < 8. Hence the answer is 8.

Upvotes: 1

Related Questions