# File: hmwk01-2-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 # .text .globl main main: la $t0, A lw $t0, 0($t0) # Read the value of “a” from memory la $t1, B lw $t1, 0($t1) # Read the value of “b” from memory. 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: la $t3, C sw $t4, 0($t3) # Store the value of “c” in memory li $v0, 10 syscall # Ready to quit .data A: .word 5 B: .word 20 C: .word 0