6

In my previous question, I inquired about converting the MAX_ARRAY() function into MIPS. I have completed that task. Now, I wish to initialize an array in my program. How might I achieve this?

       addi  $t1,$zero, 0   # initialize index i to 0
 loop: add   $t1,$t1,1         # increment index i by 1
       beq   $t1,$s2,done   # if all elements examined, quit
       add   $t2,$t1,$t1    # compute 2i in $t2
       add   $t2,$t2,$t2    # compute 4i in $t2 
       add   $t2,$t2,$s1    # form address of A[i] in $t2 
       lw    $t3,0($t2) # load value of A[i] into $t3
       slt   $t4,$t0,$t3    # maximum < A[i]?
       beq   $t4,$zero,loop # if not, repeat with no change
       addi  $t0,$t3,0         # if so, A[i] is the new maximum 
       j     loop       # change completed; now repeat
 done: 
1
  • The answers to the question you linked to show that - both dynamically and statically. Commented Sep 25, 2011 at 11:06

1 Answer 1

4

http://pages.cs.wisc.edu/~cs354-2/onyourown/arrays.html Hope this helps you... Wasn't able to find more appropriate answer

Sign up to request clarification or add additional context in comments.

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.