我想编写一个在数组中找到最大值的程序。 当我尝试启动我的程序时,我收到错误“PC发生异常= 0x0040004c”。我不知道这意味着什么,我不知道我的代码有什么问题。
.data
liste: .word 1, 2 ,3 ,41, 5, 6, 7
.text
main:
la $a0 liste #adresse des ersten Elements in $a0 gespeichert
la $a1 28($a0) #adresse des letzten Elements in $a1 gespeichert
li $v0 0 #speichere 0 in v0
tester:
beq $a0 $a1 exit #test, if we are at the end of the array
j findmax
findmax:
la $t0 ($a0) #copy a0 in t0
speichermax:
la $v0 ($t0) #adress of t0 (Maximum) in v0
lw $v1 ($v0) #value of the max in v1
loop:
la $t0 4($t0) #go to the next field content
beq $v0 $a1 exit #end of field is reached
lw $t1 ($t0)
sub $t1 $t1 $v1 # t1 = t1 - v1
bgtz $t1 speichermax
#bgt $t1 $v1 speichermax #test if t1>v1 -> yes: save the new max in v1 (über speichermax)
j loop
exit:
lw $a0 ($t0) #print the maximum
li $v0 1
syscall
li $v0 10 #exit
syscall
答案 0 :(得分:0)
Skipping the rest of the program I believe that this: la $a1, 28($a0)
is wrong. Try this: addi $s1, $a0, 28
.