Homework 2 MIPS Assembly Programming Turn in one hardcopy printout per group of all code at the beginning of class on June 10th with all group members’ names and the title “CDA 3101 HW 2” at the top of the first page, clearly printed. An electronic version (ZIP) should also be submitted on eLearning by this time. Your work should be well commented and well formed as specified in the syllabus, and must conform to the standard MIPS conventions as presented in class. Correct output does not guarantee an A! Please include the following for each applicable function: • A register map, with a human-readable name for each register used o $fp, $sp, and the $v0-$v1 registers do not need to be specified. • A stack-frame diagram (for each non-leaf procedure) • A pseudocode version of each method for which no pseudocode was previously provided Least Common Multiples Write a program that takes in an arbitrary number of unsigned integers as input and calculates their LCM (least common multiple) by prime factorization. Use the provided prime factorization algorithm (below) to find each number’s factors. The quantity of integers and the integers themselves should be specified by the user. (For a reference, see http://en.wikipedia.org/wiki/Least_common_multiple.) int* primeStart(int number) { return prime(number, 2, 0); } int* prime(int number, int factor, int factorsFound) { if(factor * factor > number) //is sqrt(factor) < number? { //if so, number is prime. //(We’ve covered the other factors.) int* factors = new int[factorsFound+1]; factors[factorsFound] = number; return factors; } if(number % factor == 0) //% = modulus, remainder op { number = number / factor; //Factor may repeat (below) int* factors = prime(number, factor, factorsFound+1); factors[factorsFound] = factor; return factors; } else return prime(number, factor+1, factorsFound); } A quick sidenote – since MIPS has two return value registers, you may wish to use the second register to hold the array length in the above two methods. Requirements: 1. You may not use the built-in MIPS instructions for multiplication – instead, write your own multiplication method, making use of the concepts presented in class. (Keep in mind that certain instructions were hinted to be helpful for this purpose.) 2. However, you may use the built-in division instructions that were presented in class. 3. The program should always give human-readable prompts that inform any users of the purpose of its requests and outputs. 4. The program must have the following methods: a. A multiplication method b. The prime factorization function + its helper function c. LCM function – takes in two prime factor lists and finds the prime factors for the least common multiple d. A “pretty printer” function that takes the address of a list of prime factors and displays them in an appropriate format 5. You may add additional methods as necessary, provided that you document their purpose well. However, you must implement the functions specified above. a. For extra credit, you may implement your own division function instead of using the MIPS instructions provided for this purpose. Grading: 1. This homework will be worth double the amount of the other homeworks that will be assigned. o Keep in mind that the point total of each homework will be scaled to match the distribution specified within the syllabus at the end of the class. 2. The grading distribution across the methods will be determined after submission to ensure fairness in point distribution. (Methods found to be more difficult by all groups may become worth less points, depending upon the reasons for the observed difficulties.) 3. The extra credit function will give up to a 10% bonus on the homework, which may result in a grade over 100%. This will not be truncated. 4. It is your responsibility to make sure that the TA can understand your homework solutions, each method will be inspected to ensure theoretical correctness in the following: a. All handling of memory and memory allocation b. Stack usage c. Translation of the given algorithms (for example, recursive functions must remain recursive) d. Use of MIPS conventions e. Logical flow of the program If the code is not understandable to the TA as written, grading will be made assuming incorrectness on the part of the programmers. 5. Each group member will be expected to contribute equally to this homework within their group. To ensure this, each student will independently turn in a list of work performed by himself (or herself) and each of his (or her) group members, as well as an assessment of performance for each member. It is possible that different group members may receive different grades. 6. Be aware that each group member will be expected to have familiarity with all parts of the program as written, as future quizzes and exams may contain questions pertaining to details of this assignment. 7. Adherence to the Student Honor Code is assumed upon turning in this assignment. All aspects of this assignment must prove to be distinct upon comparison to those of other groups.