########################################################################## # # procedures.mal # CMPE12C Lab 5 # # Cliff McIntire # # Procedures: The procedures called in the main program are not yet # implemented. You need to add code under each matching # label at the bottom of this file to implement each # procedure. You MAY add any procedures you wish. You # MAY NOT change any of the driver program # (between "START MAIN" and "FINISH MAIN") # # For a X+: The marked lines commented out in main may be # uncommented and the designated procedures may be # implemented for a X+ .data array: .word 0:20 NumPrompt: .asciiz "Please Enter a Number\n" BinPrompt: .asciiz "The Binary Representation of " FactPrompt: .asciiz "The Factorial of " SumFactPrompt: .asciiz "The Sum of Factorials of " NumArrPrompt: .asciiz "Please Enter 20 Numbers Separated by Spaces\n" UnsortedPrompt: .asciiz "Your Values in Unsorted Order Are:\n" SortedPrompt: .asciiz "Your Values in Sorted Order Are:\n" is: .asciiz " is " .text __start: # START MAIN (DO NOT MODIFY THIS SECTION!!!!) # START MAIN (DO NOT MODIFY THIS SECTION!!!!) # START MAIN (DO NOT MODIFY THIS SECTION!!!!) # START MAIN (DO NOT MODIFY THIS SECTION!!!!) # Integer in, bit string out # Prompt for an integer, get it puts NumPrompt jal getnum # Output integer in base-2 format with prompts # and newline puts BinPrompt jal putnum puts is jal putbin putc '\n' # Integer in, factorial out # Prompt for an integer, get it puts NumPrompt jal getnum # Compute factorial on integer and output with # prompts and newlines puts FactPrompt jal putnum puts is jal factorial jal putnum putc '\n' #X+# Integer in, sum of factorials out #X+ # Prompt for integer, get it #X+ puts NumPrompt #X+ jal getnum #X+ #X+ # Calculate sum of factorials and output it with #X+ # prompts and newlines. #X+ puts SumFactPrompt #X+ jal putnum #X+ puts is #X+ jal sumoffactorials #X+ jal putnum #X+ putc '\n' # NumArray in, NumArray out # Prompt for 20 integers, get them, stuff array puts NumArrPrompt jal getnumarray # Output array with prompts and newlines puts UnsortedPrompt jal putnumarray putc '\n' #X+ # Sort array and output it with prompts and newlines #X+ puts SortedPrompt #X+ jal sortarray #X+ jal putnumarray #X+ putc '\n' putc '\n' b __start # END MAIN (YOU MAY NOT MODIFY THIS SECTION!!!!) # END MAIN (YOU MAY NOT MODIFY THIS SECTION!!!!) # END MAIN (YOU MAY NOT MODIFY THIS SECTION!!!!) # END MAIN (YOU MAY NOT MODIFY THIS SECTION!!!!) # START PROCEDURES (YOU MAY (MUST) MODIFY THIS SECTION) getnum: # Strip leading spaces from input, then get an # ascii number up to a space or newline, then # store in $s0. Must be able to handle negative # numbers ( denoted by a number immediately followed # by a ! - 3! is really -3 ) putnum: # Print the value in $s0 as an ascii string. Must be able # to handle negative numbers ( denoted by a number # immediately followed by a ! - 3! is really -3) putbin: # Print the last 8 bits of $s0 factorial: # Calculate the value of ($s0)! and store in $s0 sumoffactorials: # Calculate the sum of factorials # on 1 to n, where n is the value # in $s0, then store result in $s0 # Must call 'factorial' # IMPLEMENT FOR A X+ getnumarray: # Call getnum 20 times to fill 'array' with values putnumarray: # Print each value in 'array' in stored (not sorted) # order using putnum sortarray: # Sort the elements of 'array' in ascending order # IMPLEMENT FOR A X+