Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1547
  • Last Modified:

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

0
jralexander137
Asked:
jralexander137
3 Solutions
 
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
 
Infinity08Commented:
Since it seems you decided to delete the other question instead, I'll re-post my response here :
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Infinity08Commented:
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
 
Infinity08Commented:
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
 
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
 
Infinity08Commented:
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

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now