#********************************************************************** # CSSE 232: Computer Architecture I # # File: Trivial Program 1: Calculating the Volume of a Rectangular # Prism (without using multiply) # Written: 9/21/2005, Keith Kaffenberger Team Do de-do, dum da-dum # # This file contains a Mach 5 assembly language program that uses only # the instructions # # add, or, la, lw, bne, beq # #********************************************************************** ######################## NOTE ######################## #* * #* We do not yet have anything yet that accepts * #* input from an outside source, but assume the * #* values below can be changed by the user * #* before running the actual program * #* * ###################################################### L: 2 # Arbitrary Length of Rectangular Prism W: 3 # Arbitrary Width of Rectangular Prism H: 5 # Arbitrart Height of Rectangular Pristm #---------------------------------------------------------------------- # Calculate the value of a rectangular prism #---------------------------------------------------------------------- la $t0, L # Load the address of L into a register lw $t0, $0(L) # Load the value of L into register la $t1, W # Load the address of W into a register lw $t1, $0(W) # Load the value of W into register la $t2, H # Load the address of H into a register lw $t2, $(H) # Load the value of H into register or $t3, $0, $0 # Load zero into $t3 (Loop Counter A) or $t4, $0, $0 # Load zero into $t5 (Loop Counter B) multiply1: add $t5, $t5, $t0 # Add the value in $t5 over and over add $t3, $t3, $1 # Increment Loop Counter A until it beq $t3, $t1, multiply2 # equals the value of $t1, then branch bne $0, $1, multiply1 # Or repeat this loop multiply2: add $t5, $t5, $t3 # Add the value in $t5 over and over add $t4, $t4, $1 # Increment Loop Counter A until it beq $t4, $t2, output # equals the value of $t2, then branch bne $0, $1, multiply2 # Or repeat this loop output: # Nifty code will go here once we can write things that let the user # mess with input