MIPS programming successive addition

JAO012
Messages
3
Reaction score
0

Homework Statement


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.

Homework 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.


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
 
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.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 3 ·
Replies
3
Views
14K
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
8K
  • · Replies 1 ·
Replies
1
Views
6K
Replies
7
Views
10K