2011-03-22 46 views
1

我試圖寫一個MIPS功能至極返回的最大值的位置,但我想趁這個exeption (誤差在/ home/AMS /局/ part2a線21:在0x00400028運行時異常:地址超出範圍0x00000000)陣列上MIPS大會

# 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 

有什麼建議嗎?

回答

1

您正在將$ s1設置爲0,然後嘗試對其進行解引用。也許你的意思是$ t0?

lw $t1, 0($t0) 
+0

仍然有同樣的exeption但知道錯誤在/ home/AMS /局/ part2a線20:運行在0x00400028例外:地址超出範圍0x23b8f000 – Mooh 2011-03-22 08:35:43

+1

那麼你的初始化是錯誤的,因爲它的確切地址加載$ s0與。 – 2011-03-22 08:42:55

+0

是的,你是正確的初始化有什麼問題,但我不明白什麼:/任何猜測? – Mooh 2011-03-22 08:49:29