c code -> mips code

J

jty0734

if you have mips cross compiler, please convert this c code to mips
code.

i'm try to install mips compiler 3 days, but some error fail to that.

so if you have something cross compiler c code -> mips code , please
convert this to me. thx!













#include<stdio.h>


int x[8]={-1,5,2,8,7,1,9,3};
int y[8]={-1,5,3,4,2,6,6,2};

int distance(int a,int b){

return ( (x-x[a] )*( x-x[a] ) + ( y-y[a] )*( y-y[a] ) );
}

int main()
{

int weigh[8][8]={0,};

int result[8]={-1,7,0,0,0,0,0,1};
int total [8]={0,};
int i,j;

int min;
int minindex;
/*----------------------------------------------------*/
i=1;
for1: if( i > 7 ) goto done;

j=1;
for2: if( j > 7 ) goto done2;

weigh[j] = distance(i,j);
if(i==j) weigh[j]=999;
if(j==1 || j==7 ) weigh[j]=999;
printf("%d ",weigh[j]);
j++;

goto for2;

done2:
printf("\n\n");

i++;
goto for1;


done:
/*-----------------------------------------------------*/
i=1;
for3: if(i>5) goto done3;

min=999;
j=1;

for4: if(j>6) goto done4;

if( min > weigh[ result ][j] )
{

min=weigh[ result ][j];
minindex=j;
}
j++;
goto for4;

done4:


result[i+1]=minindex;
total=weigh[ result][result[i+1]];
weigh[1][minindex]=999;
weigh[2][minindex]=999;
weigh[3][minindex]=999;
weigh[4][minindex]=999;
weigh[5][minindex]=999;
weigh[6][minindex]=999;
weigh[7][minindex]=999;

i++;
goto for3;

done3:

/*-----------------------------------------------------------*/
total[6]=distance(result[6],result[7]);


printf("%d %d %d %d %d %d %d
\n",result[7],result[6],result[5],result[4],result[3],result[2],result[1]);
printf("%d %d %d %d %d %d
%d",total[7],total[6],total[5],total[4],total[3],total[2],total[1]);


return 0;
}
 
U

user923005

if you have mips cross compiler, please convert this c code to mips
code.

i'm try to install mips compiler 3 days, but some error fail to that.

so if you have something cross compiler  c code -> mips code , please
convert this to me. thx!

#include<stdio.h>

int x[8]={-1,5,2,8,7,1,9,3};
int y[8]={-1,5,3,4,2,6,6,2};

int distance(int a,int b){

                return ( (x-x[a] )*( x-x[a] ) + ( y-y[a] )*( y-y[a] ) );
        }

int main()
{

        int weigh[8][8]={0,};

        int result[8]={-1,7,0,0,0,0,0,1};
        int total [8]={0,};
        int i,j;

        int min;
        int minindex;
/*----------------------------------------------------*/
        i=1;
        for1:   if( i > 7 ) goto done;

                j=1;
                for2:   if( j > 7 ) goto done2;

                        weigh[j] = distance(i,j);
                        if(i==j) weigh[j]=999;
                        if(j==1 || j==7 ) weigh[j]=999;
                        printf("%d  ",weigh[j]);
                        j++;

                        goto for2;

                done2:
        printf("\n\n");

                i++;
                goto for1;

        done:
/*-----------------------------------------------------*/
                i=1;
        for3: if(i>5) goto done3;

                  min=999;
                  j=1;

        for4: if(j>6) goto done4;

                                if( min > weigh[ result ][j] )
                                {

                                        min=weigh[ result ][j];
                                        minindex=j;
                                }
                                j++;
                                goto for4;

                        done4:

                        result[i+1]=minindex;
                         total=weigh[ result][result[i+1]];
                        weigh[1][minindex]=999;
                        weigh[2][minindex]=999;
                        weigh[3][minindex]=999;
                        weigh[4][minindex]=999;
                        weigh[5][minindex]=999;
                        weigh[6][minindex]=999;
                        weigh[7][minindex]=999;

                        i++;
                goto for3;

        done3:

/*-----------------------------------------------------------*/
        total[6]=distance(result[6],result[7]);

        printf("%d %d %d %d %d %d %d
\n",result[7],result[6],result[5],result[4],result[3],result[2],result[1]);
        printf("%d %d %d %d %d %d
%d",total[7],total[6],total[5],total[4],total[3],total[2],total[1]);

        return 0;



}- Hide quoted text -

- Show quoted text -


Mips is a hardware architecture. The operating system is not
specified. Could be IRIX. Could be Linux. Could be NetBSD. Could
be OpenBSD. Could be Ultrix. Could be Pyramid. Could be Windows/NT
or RISC/OS or UNIX System V or SINIX. MIPS hardware is also used in
some Video game systems.

However, today is your happy day. This program just outputs a fixed
list of items, no matter what platform you compile it for. Output is
at the bottom.

#include <stdio.h>
static const int x[8] = {-1, 5, 2, 8, 7, 1, 9, 3};
static const int y[8] = {-1, 5, 3, 4, 2, 6, 6, 2};

int distance(int a, int b)
{
return ((x - x[a]) * (x - x[a]) + (y - y[a]) * (y -
y[a]));
}
int main()
{
int weigh[8][8] = {0};
int result[8] = {-1, 7, 0, 0, 0, 0, 0, 1};
int total[8] = {0};
int i,
j;
int min;
int minindex = 0;
/*----------------------------------------------------*/
i = 1;
for1:
if (i > 7)
goto done;
j = 1;
for2:
if (j > 7)
goto done2;
weigh[j] = distance(i, j);
if (i == j)
weigh[j] = 999;
if (j == 1 || j == 7)
weigh[j] = 999;
printf("%d ", weigh[j]);
j++;
goto for2;
done2:
printf("\n\n");
i++;
goto for1;
done:
/*-----------------------------------------------------*/
i = 1;
for3:
if (i > 5)
goto done3;
min = 999;
j = 1;
for4:
if (j > 6)
goto done4;
if (min > weigh[result][j]) {
min = weigh[result][j];
minindex = j;
}
j++;
goto for4;
done4:
result[i + 1] = minindex;
total = weigh[result][result[i + 1]];
weigh[1][minindex] = 999;
weigh[2][minindex] = 999;
weigh[3][minindex] = 999;
weigh[4][minindex] = 999;
weigh[5][minindex] = 999;
weigh[6][minindex] = 999;
weigh[7][minindex] = 999;
i++;
goto for3;
done3:
/*-----------------------------------------------------------*/
total[6] = distance(result[6], result[7]);
printf("%d %d %d %d %d %d %d \n", result[7], result[6],
result[5], result[4], result[3], result[2], result[1]);
printf("%d %d %d %d %d %d %d", total[7], total[6],
total[5], total[4], total[3], total[2], total[1]);
return 0;
}
/*
999 13 10 13 17 17 999

999 999 37 26 10 58 999

999 37 999 5 53 5 999

999 26 5 999 52 20 999

999 10 53 52 999 64 999

999 58 5 20 64 999 999

999 2 29 16 20 52 999

1 6 3 4 5 2 7
0 17 5 5 52 10 2
*/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top