# File: hmwk02-1-soln.asm # Written by: Archana Chidanandan, Dec. 16, 2003 # # Given two values "a" and "b" in memory, to obtain the product "c", without # using MIPS mult, multu, mul, mulo or muluo instructions. The program must use # a loop. The product must be calculated using a procedure. # .text .globl main main: la $s0, A lw $s0, 0($s0) # Read the value of “A” from memory la $t1, B lw $s1, 0($t1) # Read the value of “B” from memory. move $a0, $s0 # Copy the arguments "A" and "B" into the argument # registers move $a1, $s1 jal Product # Call procedure "Product" move $t4, $v0 # Store return value "c" in temporary register. la $t3, C sw $t4, 0($t3) # Store the value of “c” in memory li $v0, 10 syscall # Ready to quit Product: # Procedure to determine the product move $t0, $a0 # Move the paraments into temporary registers. move $t1, $a1 li $t3, 0 # i = 0 (to keep track of the value “b” li $t4, 0 # c = 0 (initialize the result to 0) loop: beq $t3, $t1, done # while (i is not equal to b ) continue adding # a to c. add $t4, $t4, $t0 # c= c + a; addi $t3, $t3, 1 # i = i + 1 j loop done: move $v0, $t4 # Move return value "c" to the return value # register. jr $ra # Return to the calling procedure .data A: .word 5 B: .word 20 C: .word 0