MIPS programming successive addition

Click For Summary
The discussion revolves around creating a MIPS program to multiply two integers using successive addition instead of the multiplication operation. The user has successfully set up prompts and echoes for input but is struggling with implementing the loop for repeated addition. To achieve this, a loop is needed that decrements a counter based on one of the integers and adds the other integer repeatedly. The example provided illustrates how to perform the addition step-by-step. The solution requires familiarity with MIPS assembly language constructs such as loops and branch instructions.
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
 
Physics news on Phys.org
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 22 ·
Replies
22
Views
5K
  • · Replies 2 ·
Replies
2
Views
5K
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
13K
  • · Replies 12 ·
Replies
12
Views
11K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 4 ·
Replies
4
Views
10K
  • · Replies 1 ·
Replies
1
Views
3K