我该如何在MIPS中初始化一个数组?

6

在我的之前的问题中,我询问了将MAX_ARRAY()函数转换为MIPS的方法。我已经完成了这个任务。现在,我希望在我的程序中初始化一个数组。我该如何实现?

       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: 

你链接的问题的答案表明 - 动态和静态两种方式都可以。 - user786653
1个回答

3

这个链接可以帮助你了解数组相关的IT技术知识,虽然没有更适合的答案。


5
该页面已经移动到这里:http://pages.cs.wisc.edu/~smoler/cs354/onyourown/arrays.html。 - Jeff Burka

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接