tags:

views:

97

answers:

1

Possible Duplicate:
Convert java to mips

i write this code in java now i want to convert it to mips i dont learn mips can any help me ????????

now explain code

this code is to

Comparing each character in the first string with the character at the same index in the second string and compute the number of different characters in the two strings.

(ex. Strings_ Difference("atalk","took")= diff is = 5 this code compare to string and the diff is 5 why?

because in string 1 first char is a and in second is t in string 1 second char is t and in string 2 second is o ect... this is how to find diff

and Compute the difference between the two strings in length.(ex. Strings_Difference("tall","talls") =1 because the string books has one character more than the string book).

after compute differance this is output =1 but i write more string to explain it

The difference between the two strings in length = 1


public class NewClass1 {


public static void main (String args[] ) {

        //two trings to be compare

         String s1 = "ataok";
         String s2 = "took";

// integer to find differance between two string

         int differance =s1.length()-s2.length();

// method to compare each char in two strings


         diff(s1,s2);

// to print output The difference between the two strings in length 

         System.out.println( "  The difference between the two strings in length =  " + differance);


                                              }



//method to compare

        public static void diff(String s1 , String s2){

//define two array of char to put strings in it

         char []a;
         char []b;

// max to find the longer string to be the dimention of two array (same dim)

         int max=0;

//variable to be increase when char in string1 != char in string 2


         int diff=0;


// find max string in lenght

         if(s1.length()>s2.length())
              max =s1.length();

         else max =s2.length();


//put strings in array of char

         a = new char [max];
         b = new char [max];

         for(int i=0 ; i<s1.length() ; i++){
              a[i]=s1.charAt(i);
                                           }


         for(int i=0 ; i<s2.length() ; i++){
              b[i]=s2.charAt(i);
                                           }

// copmare two string each char

      for (int i=0 ; i<max ;i++){
            if (a[i]== b[i]);

                else diff+=1;
                                }

         System.out.println("  diff is = " + diff );

        }
}
+3  A: 

The reason your questions are getting closed is that the question is not a sensible one. Java is a high level language, and MIPS is an assembler language, so 'converting' this code is not a sensible thing to do. You should write new MIPS code to do whatever you want to do. The alternative is to find a Java compiler that writes MIPS code as output, though I have never heard of such a thing.

The second is that you are in essence asking people to do a whole lot of work for you. If this is homework, then the point of it is that you should do it yourself - not ask people to spend hours or days doing a task that is supposed to be teaching you something. The point is probably to get you to learn MIPS code, so go ahead and learn it. If you get someone else to do your assignment for you you are a) cheating your college, who may possibly fail you for the whole course if they find out and b) cheating youself, as you are missing the opportunity to learn something important.

If you are looking for references or help to get you started writing MIPS code, then please ask that, not ask people to do your homework for you.

DJClayworth