# Homework Help: MIPS programming successive addition

1. Feb 15, 2012

### JAO012

1. The problem statement, all variables and given/known data
I need to create a program that will prompt for two integers, echo those integers, and then multiply them without using the multiplication operation and report the result.

2. Relevant equations
The following is what I have so far. The prompts and echoes work, however I do not know how to actually perform the successive addition. I know I need to set up some sort of loop, but I am new to MIPS and assembly and am stuck.

3. The attempt at a solution

.data
prompt_in:
.asciiz "Please input first integer: "
prompt_ina:
.asciiz "\nPlease input second integer: "
prompt_out:
.asciiz "\nThe result is "
num1:
.word 0
num2:
.word 0
echo:
.asciiz "You have input "
echo1:
.asciiz "You have input "
result:
.word 0
.text
.globl main
main:
la $a0,prompt_in li$v0,4
syscall

li $v0,5 syscall sw$v0,num1

la $a0,echo li$v0,4
syscall

lw $a0,num1 li$v0, 1
syscall

la $a0,prompt_ina li$v0,4
syscall

li $v0,5 syscall sw$v0,num2

la $a0,echo1 li$v0,4
syscall

lw $a0,num2 li$v0,1
syscall

2. Feb 15, 2012

### Staff: Mentor

Suppose the input numbers to multiply are 4 and 11. The simplest way to get the product is to multiply them directly, but since you are not allowed to do this, you will need to perform repeated addition, something like this:

0 + 11 = 11 (step 1)
11 + 11 = 22 (step 2)
22 + 11 = 33 (step 3)
33 + 11 = 44 (step 4)

There are 4 steps above, which corresponds to one of the two multipliers, with the other being what we added repetitively.

You'll need to implement a loop that does this, using a register that counts down by being decremented, and a branch instruction of some kind. Look through your class notes or textbook or whatever, to see if there are any similar examples.