c code -> mips code

Discussion in 'C Programming' started by jty0734@naver.com, May 14, 2008.

  1. Guest

    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;
    }
     
    , May 14, 2008
    #1
    1. Advertising

  2. user923005 Guest

    On May 14, 3:18 am, 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-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[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
    */[/i][/i][/i][/i]
     
    user923005, May 14, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Klejmann

    data hazards and the mips

    Klejmann, Jun 17, 2004, in forum: VHDL
    Replies:
    1
    Views:
    1,646
    Just an Illusion
    Jun 18, 2004
  2. Andreas Weichert
    Replies:
    1
    Views:
    775
    Peter van Merkerk
    Nov 25, 2003
  3. Milk
    Replies:
    2
    Views:
    572
    Kevin Goodsell
    Apr 14, 2004
  4. Replies:
    0
    Views:
    482
  5. waxinwaxout
    Replies:
    8
    Views:
    1,422
    Matthias Buelow
    Dec 10, 2007
Loading...

Share This Page