Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- main:
- li $s0, 0 # y = 0
- li $a0, 2 # first argument, a = 2
- li $a1, 3 # second argument, b = 3
- jal multiplyNumbers # call the function 'multiplyNumbers'
- addi $s0, $v0, 0 # y = multiplyNumbers(2, 3)
- j done # end the program
- multiplyNumbers: # function "multiplyNumbers"
- li $t0, 0 # i = 0
- li $v0, 0 # product = 0
- j multiplyNumbersLoop # initiate the loop
- multiplyNumbersLoop: # equivalent to the "for" loop
- beq $t0, $a1, multiplyNumbersReturn # if (i == b) return
- add $v0, $v0, $a0 # product += a
- addi $t0, $t0, 1 # i++
- j multiplyNumbersLoop # continue the loop
- multiplyNumbersReturn: # return the product
- jr $ra # jump to line 6 (addi ...)
- done: # end the program
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement