Hello all, I'm new to assembly and need help with a program. The problem is in the "sumup" procedure, I think it is with "add $t3, $t3, $t2". Basically I'm trying to do "sum = sum + val" with that line, but every time I run the program, I get the output 0. Any help is appreciated!

	.data

str2: .asciiz "Enter the total number of values "
str1: .asciiz "Enter the next value "
newln: .asciiz "
"
str3: .asciiz "The sum of the values in the array is "
total: .word 0
val: .word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
sum: .word 0

.text
.globl main
main:
addi $sp, $sp, -4
sw $ra, 0($sp)
li $v0, 4
la $a0, str2
  syscall
li $v0, 5
  syscall
sw $v0, total

jal inproc

jal outproc

jal sumup


lw $ra, 0($sp)
addi $sp, $sp, 4
jr $ra



.text
inproc: addi $sp, $sp, -4
sw $ra, 0($sp)
la $t2, val
lw $t1, total
loop: slti $t0, $t1, 1
bne $t0, $zero, out
li $v0, 4
la $a0, str1
  syscall

li $v0, 5
  syscall
sw $v0, 0($t2)
addi $t2, $t2, 4
addi $t1, $t1, -1
j    loop

out: lw $ra, 0($sp)
addi $sp, $sp, 4
jr $ra



.text

outproc:addi $sp, $sp, -4
sw $ra, 0($sp)
la $t2, val
lw $t1, total
loop1: slti $t0, $t1, 1
bne $t0, $zero, out1
li $v0, 4
la $a0, newln
  syscall
li $v0, 1
lw $a0, 0($t2)
  syscall
addi $t2, $t2, 4
addi $t1, $t1, -1
j loop1

out1: li $v0, 4
la $a0, newln
  syscall


.text

sumup:  addi $sp, $sp, -4
sw $ra, 0($sp)
la $t2, val
lw $t1, total
li $v0, 4
la $a0, newln
  syscall
la $a0, str3
  syscall
loop2:  slti $t0, $t1, 1
bne $t0, $zero, out2
addi $t2, $t2, 4
add $t3, $t3, $t2
addi $t1, $t1, -1
j loop2
out2:
lw $t3, sum
li $v0, 1
lw $a0, sum
  syscall
Posted on 2010-10-25 17:51:26 by DSully26