0
votes

I'm new in this (the website and mips/mars) and I really could use your help.
I'm trying to make a program using MARS that takes integers from the user and later show the sum of those numbers. The problem is that the user sets the amount of integers to put and that I must use a loop to save the integers and make the sum, but I have not been able to figure a way to save each integer in a different register (I don't know other way to store the numbers).
I've been searching but I can't find an answer.

1

1 Answers

1
votes

Don't save each integer in a separate register. Instead keep a running total.

Consider the following:

Prompt user for number of integers to be read. Store in $t0
$t1 = 0
$t2 = 0
while ($t1 < $t0) {
    Prompt user for number. Store in $t3
    $t2 = $t2 + $t3
    $t1 = $t1 + 1
}

Output sum, which is now in $t2