0

I need this translated in MIPS can anyone help me out?

#include <stdio.h>
int n;
int row[8], s = 0;
bool safe(int x, int y)
{
        int i;
        for (i = 1; i <= y; i++)
                if (row[y - i] == x || row[y - i] == x - i || row[y - i] == x + i) return false;
		
        return true;
		
}
void putboard()
{
		 
        printf("\nSolution #%d:\n---------------------------------\n", ++s);
        int x,y;
        for (y = 0; y < 8; printf("|\n---------------------------------\n"), y++)
                for (x = 0; x < 8; printf(x++ == row[y] ? "| Q " : "|   "));
	
}
int main(int y)
{
	
        int x;
        for (x = 0; x < 8; x++)
                if (safe(row[y - 1] = x, y - 1))
                        if (y < 8) main(y + 1);
                        else putboard();
	
      return 0;
}
2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by Duoas
0

This is my main prob not sure how to turn this into MIPS

if (row[y - i] == x || row[y - i] == x - i || row[y - i] == x + i) return false;
0

Break it down into its constituent parts:

int yi = y - i;
  int val = row[ yi ];

  if (val == x) goto return_false_part;
  if (val == x - i) goto return_false_part;
  if (val == x + i) goto return_false_part;

Stick that in the loop, and add return false and return true parts, and you should be able to translate it easily.

Hope this helps.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.