Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

MIPS Assembly Programming, Least Common Multiples - Homework 2 | CDA 3101, Assignments of Computer Architecture and Organization

Material Type: Assignment; Class: INTRO TO COMPU ORGNZN; Subject: COMPUTER DESIGN/ARCHITECTURE; University: University of Florida; Term: Unknown 1989;

Typology: Assignments

Pre 2010

Uploaded on 09/17/2009

koofers-user-ix0
koofers-user-ix0 🇺🇸

10 documents

1 / 3

Toggle sidebar

Related documents


Partial preview of the text

Download MIPS Assembly Programming, Least Common Multiples - Homework 2 | CDA 3101 and more Assignments Computer Architecture and Organization in PDF only on Docsity! 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.
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved