MIPS programming successive addition

In summary, the task is to create a program in MIPS assembly that prompts for two integers, echoes them, and then multiplies them without using the multiplication operation. This can be achieved by performing repeated addition using a loop and a register to keep track of the count. It is recommended to refer to class notes or textbook examples for guidance.
  • #1
JAO012
3
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
  • #2
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.
 

1. What is MIPS programming successive addition?

MIPS programming successive addition is a method used in MIPS assembly language to add a series of numbers together. It involves using the addition operation to add each number in the series to a running total, resulting in a final sum.

2. How does MIPS programming successive addition work?

In MIPS programming successive addition, the first number in the series is added to a register, which serves as the running total. Then, each subsequent number is added to this register using the addition operation, until all numbers in the series have been added. The final value in the register is the sum of all the numbers in the series.

3. What is the benefit of using MIPS programming successive addition?

MIPS programming successive addition is a useful technique for adding a large series of numbers in a relatively efficient way. It avoids the need to write out a separate addition operation for each number, which can save time and space in the code.

4. Are there any limitations to using MIPS programming successive addition?

One limitation of using MIPS programming successive addition is that it can only be used for adding numbers. It cannot perform other mathematical operations such as subtraction or multiplication. Additionally, the series of numbers being added must be known beforehand and cannot be dynamically generated during execution.

5. Can MIPS programming successive addition be used in other programming languages?

While MIPS programming successive addition is a technique specific to the MIPS assembly language, similar methods can be used in other programming languages. For example, the concept of a running total can be implemented using a loop or recursion in higher-level languages like C or Java.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
4
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
22
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
12K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
12
Views
10K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
9K
Back
Top