Question: Magic Squares Objective : Implement a non-trivial algorithm in MIPS assembly language. (.asm file) Please write in MIPS code that is compatible with MARS 4_5

Magic Squares Objective: Implement a non-trivial algorithm in MIPS assembly language. (.asm file) Please write in MIPS code that is compatible with MARS 4_5 (MIPS Assembler and Runtime Simulator).

Magic Squares Objective: Implement a non-trivial algorithm in MIPS assembly language. (.asm

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 research before tackling this program. I have a working source code in C++ but I need to convert it into MIPS Assembly language. (.asm file)

C++ code:

#include #include #include #include #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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!