簡體   English   中英

MIPS 匯編上的陣列

[英]array on MIPS Assembly

我正在嘗試編寫一個返回最大值位置的 mips 函數,但我得到了這個例外(/home/ams/Bureau/part2a 第 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

有什么建議嗎?

您將 $s1 設置為 0,然后嘗試取消引用它。 也許你的意思是$t0?

lw   $t1, 0($t0)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM