Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   c code -> mips code (http://www.velocityreviews.com/forums/t614764-c-code-mips-code.html)

 jty0734@naver.com 05-14-2008 10:18 AM

c code -> mips code

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[b]-x[a] )*( x[b]-x[a] ) + ( y[b]-y[a] )*( y[b]-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[i][j] = distance(i,j);
if(i==j) weigh[i][j]=999;
if(j==1 || j==7 ) weigh[i][j]=999;
printf("%d ",weigh[i][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[i] ][j] )
{

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

done4:

result[i+1]=minindex;
total[i]=weigh[ result[i]][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;
}

 user923005 05-14-2008 10:33 PM

Re: c code -> mips code

On May 14, 3:18*am, jty0...@naver.com wrote:
> 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[b]-x[a] )*( x[b]-x[a] ) + ( y[b]-y[a] )*( y[b]-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[i][j] = distance(i,j);
> * * * * * * * * * * * * if(i==j) weigh[i][j]=999;
> * * * * * * * * * * * * if(j==1 || j==7 ) weigh[i][j]=999;
> * * * * * * * * * * * * printf("%d *",weigh[i][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[i] ][j] )
> * * * * * * * * * * * * * * * * {
>
> * * * * * * * * * * * * * * * * * * * * min=weigh[ result[i] ][j];
> * * * * * * * * * * * * * * * * * * * * minindex=j;
> * * * * * * * * * * * * * * * * }
> * * * * * * * * * * * * * * * * j++;
> * * * * * * * * * * * * * * * * goto for4;
>
> * * * * * * * * * * * * done4:
>
> * * * * * * * * * * * * result[i+1]=minindex;
> * * * * * * * * * * * * *total[i]=weigh[ result[i]][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[b] - x[a]) * (x[b] - x[a]) + (y[b] - y[a]) * (y[b] -
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[i][j] = distance(i, j);
if (i == j)
weigh[i][j] = 999;
if (j == 1 || j == 7)
weigh[i][j] = 999;
printf("%d ", weigh[i][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[i]][j]) {
min = weigh[result[i]][j];
minindex = j;
}
j++;
goto for4;
done4:
result[i + 1] = minindex;
total[i] = weigh[result[i]][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
*/

 All times are GMT. The time now is 02:42 PM.