views:

166

answers:

1

I'm having problems getting my processor to simulate correctly and I think I've narrowed it down to the program I'm giving it.

1.  li    $R1, 0
2.  li    $R2, 0x100
3.  li    $R6, 1
4.  li    $R8, 0
5.  li    $R9, 20

6.  lw    $R3, 0($R1)
7.  lw    $R4, 4($R1)
8.  add  $R5, $R3, $R4
9.  srlv    $R5, $R5, $R6
10. sw   $R5, 0($R2)
11. addi    $R1, $R1, 4
12. addi    $R2, $R2, 4
13. addi    $R8, $R8, 1
14. slt     $R7, $R8, $R9
15. bne  $R7, $zero,  -9

It should iterate through the bottom portion 20 times and then exit. I'm particularly unsure about the branch instruction but I can't find anything wrong with it so : /

+1  A: 

So, you start with R8 as 0 and R9 as 20. Then in step 13 you add one to R8, then set R7 if R8 is less than R9 (which it will be on the first 19 iterations). Then you branch if R7 is set. Loop seems fine to me.

I don't recall what bnq does... Doesn't bne work here?

WhirlWind
I'm not sure what bnq does either. It might be a combonation of beq and bne haha. Editing that now. So the -9 does workin the bne statement?
John Moffitt
Yeah, I think it should... It's been awhile since I messed with mips, but I was thinking you had to multiply by 4 to get the offset, but I think the CPU does that for you.
WhirlWind