SHARE
TWEET

Untitled

a guest Dec 9th, 2018 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. main:
  2.     li $s0, 0                               # y = 0
  3.     li $a0, 2                               # first argument, a = 2
  4.     li $a1, 3                               # second argument, b = 3
  5.     jal multiplyNumbers                     # call the function 'multiplyNumbers'
  6.     addi $s0, $v0, 0                        # y = multiplyNumbers(2, 3)
  7.     j done                                  # end the program
  8.  
  9. multiplyNumbers:                            # function "multiplyNumbers"
  10.     li $t0, 0                               # i = 0
  11.     li $v0, 0                               # product = 0
  12.     j multiplyNumbersLoop                   # initiate the loop
  13.  
  14. multiplyNumbersLoop:                        # equivalent to the "for" loop
  15.     beq $t0, $a1, multiplyNumbersReturn     # if (i == b) return
  16.  
  17.     add $v0, $v0, $a0                       # product += a
  18.     addi $t0, $t0, 1                        # i++
  19.  
  20.     j multiplyNumbersLoop                   # continue the loop
  21.  
  22. multiplyNumbersReturn:                      # return the product
  23.     jr $ra                                  # jump to line 6 (addi ...)
  24. done:                                       # end the program
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top