MIPS ASSEMBLY LINKED LIST Context: In memory, the linked lists your utilities wi
ID: 3594592 • Letter: M
Question
MIPS ASSEMBLY LINKED LIST
Context:
In memory, the linked lists your utilities will work with are implemented as follows: each element
consists of 2 parts: pointerToNext, and value. Each part is a 32-bit MIPS word in memory. The two parts
are located in successive word addresses, with the pointerToNext being first. For example, if the byte
address of the pointerToNext is 100, then the byte address of the value will be 104. Remember, MIPS
memory is byte addressable. In the last element of the linked list, the pointerToNext has value 0, in other words it is the null pointer.This means that there is not any next element. But of course the last element still has a value.
Q) Write a MIPS program named as _main that works as the main program that calls
linked list utility functions, depending on user selection. This program outputs a message, then lists the
menu options and gets the user selection, then calls the chosen routine, and repeats. (A simple menu)
Explanation / Answer
Required solution:
public class Fraction {
// Instance variables
private int numerator; // Numerator of fraction
private int denominator; // Denominator of fraction
// Constructors
public Fraction() {
numerator = 0;
denominator = 1;
}
public Fraction(int num) {
numerator = num;
denominator = 1;
}
public Fraction(int num, int denom) {
numerator = num;
denominator = denom;
}
// Instance methods
public int getNumerator() {
return numerator;
}
public int getDenominator() {
return denominator;
}
public Fraction divide(Fraction f) {
return new Fraction(numerator * f.denominator, f.numerator
* denominator);
}
public void scaleup(int factor) {
numerator = numerator * factor;
}
public void scaledown(int factor) {
if (factor == 0) {
System.out.println("Warning cannot scale down with 0");
System.exit(0);
}
denominator = denominator * factor;
}
public void scale(boolean flag, int factor) {
if (flag)
scaleup(factor);
else
scaledown(factor);
}
public Fraction add(Fraction f) {
int num = numerator * f.denominator + f.numerator * denominator;
int denom = denominator * f.denominator;
return new Fraction(num, denom);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.