mips - Memory addresses in assembly -
i cannot figure out going wrong here. attempting store 10 integers in memory , access each of them in order. here current code:
.data # data declaration section strinmsg: .asciiz "please enter integer:" .align 2 memaddr: .space 40 .text main: #get 10 integers , store them in $t0 la $t0, memaddr #$t0 - 40 = first element in array add $t3, $zero, $zero add $t1, $zero, 10 loop: la $a0,strinmsg add $v0, $zero, 4 syscall add $v0, $zero, 5 syscall sw $v0, 0($t0) add $s1, $s1, 4 sub $t1, $t1, 1 bgtz $t1, loop #la $a0, memaddr #sub $t0, $t0, 40 #j quicksort sub $t0, $t0, 40 #<--- problem line lw $t3, 0($t0) add $a0, $t3, $zero addi $v0, $zero, 1 syscall
what happens correctly gets 10 integers user, , if rid of problem line print last element expected because memory address stored in $t0. thought subtract 40 bring front outputs 0. how can first element?
you're never incrementing $t0
within loop, you'll writing values same address, , when subtract 40 after end of loop end pointing @ memaddr - 40
.
perhaps line add $s1, $s1, 4
meant add $t0, $t0, 4
?