1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

MIPS programming successive addition

  1. Feb 15, 2012 #1
    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. jcsd
  3. Feb 15, 2012 #2

    Mark44

    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.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: MIPS programming successive addition
  1. Short MIPS Program (Replies: 9)

  2. Mips subroutines (Replies: 1)

  3. MIPS help (Replies: 1)

  4. Relocation Table MIPS (Replies: 4)

Loading...