Convert from C to MIPS

What is the MIPS conversion of this C code?

#include<stdio.h>
#include<math.h>
void hanoi(int x, char from,char to,char aux)
{
 
if(x==1)
{
printf("Move Disk From %c to %c\n",from,to);
}
else
{
hanoi(x-1,from,aux,to);
printf("Move Disk From %c to %c\n",from,to);
hanoi(x-1,aux,to,from);
}
 
}
int main()
{
 int disk;
 int moves;
 printf("Enter the number of disks you want to play with:");
 scanf("%d",&disk);
 moves=pow(2,disk)-1;
 printf("\nThe No of moves required is=%d \n",moves);
 hanoi(disk,'A','C','B');
return 0;
 }

Open in new window

jralexander137Asked:
Who is Participating?
 
Infinity08Connect With a Mentor Commented:
Setting up a cross compiler is not a trivial thing, but it's not very complicated either.

A straightforward way, is to build gcc from source (after configuring it to generate MIPS code). Depending on your needs, you might also need to build a cross-assembler and cross-linker (as well as probably some runtime libraries).

As I said, I didn't do any cross compiling with Cygwin yet, so I can't help you with specifics.

Here's some short overviews of how to build a cross-compiler with gcc :

        http://gcc.gnu.org/wiki/Building_Cross_Toolchains_with_gcc
        http://wiki.osdev.org/GCC_Cross-Compiler

Also have a look at crosstool, which will probably make life a little easier for you :

        http://kegel.com/crosstool/
0
 
Infinity08Commented:
I assume that this question is superseded by your other question (http://www.experts-exchange.com/Programming/Languages/C/Q_26604107.html), so I'll ask that this one gets deleted (since duplicate questions aren't allowed).
0
 
Infinity08Commented:
(or better yet, you can delete it yourself)
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
Infinity08Commented:
Since it seems you decided to delete the other question instead, I'll re-post my response here :
0
 
Infinity08Connect With a Mentor Commented:
You'll need a MIPS cross compiler, and then you can use the -S command line option for gcc to generate the assembly code.

I've never done cross compilation for MIPS under Cygwin, so I can't give you specific instructions, but I'm sure that you can find some via Google.

The -S command line option is as simple to use as :

        gcc -S code.c
0
 
masheikCommented:
Hi,

    The below gcc mips doc contains list of options that you can use with ,

 http://gcc.gnu.org/onlinedocs/gcc-3.3.6/gcc/MIPS-Options.html

    gcc -S --march=mips1 Example.c
0
 
jralexander137Author Commented:
I have no idea how to set up the cross compiler for MIPS...I've been trying for several hours now with no luck. Any chance you could just help me manually convert it unless you know how to get this cross compiler set up?
0
 
jralexander137Author Commented:
Well I'm in the process of trying to install a cross compiler but in the mean time any links/information on possibly converting each line to MIPs by hand?
0
 
Infinity08Commented:
That's just a matter of writing the code in MIPS assembly from scratch (following the same outline as in the C code). How good are you with MIPS assembly ?
0
 
jralexander137Author Commented:
Not good at all to be honest....I have little to no idea on even where to begin. I do know how to read MIPs relatively well but writing based on C code I have pretty much no idea.
0
 
jralexander137Author Commented:
If you know of any websites or something that would help me that would be great.
0
 
Infinity08Connect With a Mentor Commented:
You will probably have a big help with SPIM (a simulator/debugger for MIPS) :

        http://pages.cs.wisc.edu/~larus/spim.html

Note that that page also contains links to further information that will probably be useful :

        http://pages.cs.wisc.edu/~larus/spim.html#information

There are also plenty of books and tutorials to be found on writing assembly for MIPS.
0
 
evilrixSenior Software Engineer (Avast)Commented:
This question has been classified as abandoned and is being closed as part of the Cleanup Program. See my comment at the end of the question for more details.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.