tags:

views:

675

answers:

1

I am just starting to lean MIPS assembly, and I am trying to write a simple while loop. It will be equivilent to the C code:

int A[5];

for(i=0;i<5;i++) A[i]=i;

So I know I can use beq to make a while loop, but I don't know how to increment the memory address each time to go to the next register. I think maybe the slt operand may be useful, but I don't know.

A: 

assuming $3 points to A[]

lis $4
.word 4
lis $5
.word 1
add $7, $4, $5 ;$7 = 5
add $6, $0, $0 ;$6 = 0

loop:
sw $6, 0($3)
add $3, $4, $3 ;point to next "int"
add $6, $5, $6 ;add 1 to our counter
bne $7, $6, loop ;we will stop at 5
verhogen
Won't this just overwrite what was in $3 each iteration of the loop?
aloishis89
Actually I got the sw syntax wrong. So, I flipped the 2 registers. "sw" doesn't overwrite any register, it simply writes to the location pointed to by the register between brackets.
verhogen