如何在 MIPS 中初始化数组?

发布于 2024-12-06 12:04:53 字数 818 浏览 0 评论 0原文

在我的上一个问题中,我询问了如何将 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: 

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: 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冰之心 2024-12-13 12:04:53

http://pages.cs.wisc.edu/~cs354-2 /onyourown/arrays.html
希望这对您有帮助...无法找到更合适的答案

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文