MIPS programming successive addition

Click For Summary
SUMMARY

The discussion focuses on creating a MIPS assembly program that multiplies two integers using successive addition instead of the multiplication operation. The provided code successfully prompts for two integers and echoes them back, but lacks the implementation of the loop required for repeated addition. To achieve the multiplication, the program must utilize a loop that decrements a counter while adding one of the integers to an accumulator. This method effectively simulates multiplication through iterative addition.

PREREQUISITES
  • Understanding of MIPS assembly language syntax and structure
  • Familiarity with MIPS system calls for input and output
  • Knowledge of loop constructs and branch instructions in assembly programming
  • Basic concepts of integer operations and memory management in MIPS
NEXT STEPS
  • Implement a loop in MIPS assembly to perform repeated addition for multiplication
  • Explore MIPS branch instructions such as BEQ and BNE for loop control
  • Review MIPS assembly examples that demonstrate iterative processes
  • Learn about MIPS registers and their usage in arithmetic operations
USEFUL FOR

Students learning MIPS assembly programming, educators teaching computer architecture, and anyone interested in understanding low-level programming techniques for arithmetic operations.

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