main:
la $t3 array
loop:
la $a0, msg1 #output message
li $v0, 4
syscall
li $v0, 5 #read in user input
syscall
move $t0, $v0
beq $t0, -99, endloop
beq $t1,20,endloop #get user input up to 20 times
addi $t1, $t1, 1
sw $t0,($t3)
addi $t3,$t3,4
b loop #loop until it reaches 20
endloop:
li $v0,4
la $a0, msg2
syscall
li $v0, 1
move $a0, $t1
syscall
li $v0, 4
la $a0, newline
syscall
li $t5, 0
#t1 counter
#t3 array address
printloop:
beq $t5, $t1, printend
lw $a0,4($t3)
li $v0, 1
syscall
addi $t5, $t5, 1
addi $t3, $t3, 4
j printloop
printend:
} before i move to adding array value i was trying to make sure that when user enters values its being stored into array. but i dont know if its being stores because when i print its only printing zeros. can anyone tell me if my array loop is wrong or my print loop. Thanks,
Pretty simple problem here.
Before the printloop
you've forgotten to reload the starting address of array
into $t3
.
Add la $t3 array
just before the printloop
label.
Also, I don't know why you're loading at a 4 offset: lw $a0,4($t3)
. Use a zero offset instead: lw $a0,0($t3)
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.