MIPS 组件上的阵列

发布于 2024-10-24 06:39:14 字数 1164 浏览 5 评论 0原文

我正在尝试编写一个返回最大值位置的 mips 函数,但我收到此异常 (/home/ams/Bureau/part2a line 21 中的错误:0x00400028 处的运行时异常:地址超出范围0x00000000)

# MIPS assembly code

# $s0 = array base address, $s1 = i
# initialization code

main: lui  $s0, 0x23B8           # $s0 = 0x23B80000
     ori  $s0, $s0, 0xF000   # $s0 = 0x23B8F000
     addi $s1, $0, 0            # i = 0
     addi $t2, $0, 1000      # $t2 = 1000
     addi $t3, $0, 0            # $t3 =   max
     addi $s4, $0 , 0           #  $s4 = max indice

max:
loop: slt  $t0, $s1, $t2      # i < 1000?
     beq  $t0, $0, done      # if not then done
     sll $t0, $s1, 2              # $t0 = i * 4 
     add  $t0, $t0, $s0      # address of array[i]
     
     
     lw   $t1, 0($t0)        # $t1 = array[i] ERROR HERE 
     slt $t5, $t3, $t1      # max < array[i]
     beq $t5, $0,else   # if not then ense
     addi $t3,$t1, 0    # $t3 =: array[i]
     addi $s4, $s1,0    # $s4 =: i 
     #end
     
     else:   
     addi $s1, $s1, 1        # i = i + 1
     j    loop               # repeat

done: 
    addi  $v0, $s4, 0        # retval = max
    jr    $ra                # Return

请问有什么建议吗?

I'm trying to write a mips function which return the position of the maximum value but I'm getting this exeption (Error in /home/ams/Bureau/part2a line 21: Runtime exception at 0x00400028: address out of range 0x00000000)

# MIPS assembly code

# $s0 = array base address, $s1 = i
# initialization code

main: lui  $s0, 0x23B8           # $s0 = 0x23B80000
     ori  $s0, $s0, 0xF000   # $s0 = 0x23B8F000
     addi $s1, $0, 0            # i = 0
     addi $t2, $0, 1000      # $t2 = 1000
     addi $t3, $0, 0            # $t3 =   max
     addi $s4, $0 , 0           #  $s4 = max indice

max:
loop: slt  $t0, $s1, $t2      # i < 1000?
     beq  $t0, $0, done      # if not then done
     sll $t0, $s1, 2              # $t0 = i * 4 
     add  $t0, $t0, $s0      # address of array[i]
     
     
     lw   $t1, 0($t0)        # $t1 = array[i] ERROR HERE 
     slt $t5, $t3, $t1      # max < array[i]
     beq $t5, $0,else   # if not then ense
     addi $t3,$t1, 0    # $t3 =: array[i]
     addi $s4, $s1,0    # $s4 =: i 
     #end
     
     else:   
     addi $s1, $s1, 1        # i = i + 1
     j    loop               # repeat

done: 
    addi  $v0, $s4, 0        # retval = max
    jr    $ra                # Return

any suggestion please?

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

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

发布评论

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

评论(1

风尘浪孓 2024-10-31 06:39:14

您将 $s1 设置为 0,然后尝试取消引用它。也许你的意思是$t0?

lw   $t1, 0($t0)

You are setting $s1 to 0, and then trying to dereference it. Perhaps you meant $t0?

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