Question
Magic Squares Objective : Implement a non-trivial algorithm in MIPS assembly language. Please write in MIPS code that is compatible with MARS 4_5 (MIPS simulator).
Magic Squares
Objective: Implement a non-trivial algorithm in MIPS assembly language.
Please write in MIPS code that is compatible with MARS 4_5 (MIPS simulator).
Miscellaneous: This program must use functions and arrays. It is your decision how many functions are used and how they are defined.
There is an algorithm for creating magic squares; make sure you do your reserach before tackling this program.
I have a working source code in C++ but I need to convert it into MIPS Assembly language.
C++ code:
#include
using namespace std;
ofstream myfile;
// A function to generate odd sized magic squares void generateSquare(int n) { int x, y;
// Variable sized 2D array int **magicSquare = new int* [n]; for (x = 0; x
// Initializing the array to all zeros for(x = 0; x
// Initialize position for 1 int i = n/2; int j = n-1;
// One by one put all values in magic square for (int num = 1; num
j++; i--; //1st condition }
// print magic square myfile
for(i=0; i // Driver program to test above function int main() { int n; // Works only when n is odd myfile.open ("output.txt"); do { cout > n; if(n%2!=0) generateSquare(n); else if(n != 0) cout Problem: A Magic Square of order N consists of N'squares, each of which contains a number from 1 through N such that the rows, columns, and diagonals sum to the same thing (called the magic sum). For example, the following is a magic square of order 3 with a magic sum of 15 6 1 7 4 Input: Your program should ask the user to enter an odd integer. For the purposes of this program, treat the input as an unsigned short. Every odd number up to 999 is valid for this program. The program should continue prompting for numbers and printing magic squares until the user enters a zero. If an even number is entered, print an appropriate error message and prompt the user to enter another number. Output: The program should output the magic squares to a text file. You don't need to print the boxes around the numbers, but arrange the numbers in columns and rows so the square is readable using print formatting. In addition to the magic square, also print out the magic sum. Problem: A Magic Square of order N consists of N'squares, each of which contains a number from 1 through N such that the rows, columns, and diagonals sum to the same thing (called the magic sum). For example, the following is a magic square of order 3 with a magic sum of 15 6 1 7 4 Input: Your program should ask the user to enter an odd integer. For the purposes of this program, treat the input as an unsigned short. Every odd number up to 999 is valid for this program. The program should continue prompting for numbers and printing magic squares until the user enters a zero. If an even number is entered, print an appropriate error message and prompt the user to enter another number. Output: The program should output the magic squares to a text file. You don't need to print the boxes around the numbers, but arrange the numbers in columns and rows so the square is readable using print formatting. In addition to the magic square, also print out the magic sum
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started