Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 simulator).

I've getting codes that have errors so please upload the working MIPS code.

image text in transcribed

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) I will post C++ code so you can use it as a reference.

#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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

9th Edition

B01JXPZ7AK, 9780805360479

More Books

Students also viewed these Databases questions