?
Solved

Convert from C to MIPS

Posted on 2010-11-09
14
Medium Priority
?
1,470 Views
Last Modified: 2013-11-17
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
Comment
Question by:jralexander137
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
14 Comments
 
LVL 53

Expert Comment

by:Infinity08
ID: 34099678
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
 
LVL 53

Expert Comment

by:Infinity08
ID: 34099681
(or better yet, you can delete it yourself)
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 34099823
Since it seems you decided to delete the other question instead, I'll re-post my response here :
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 53

Assisted Solution

by:Infinity08
Infinity08 earned 2000 total points
ID: 34099824
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
 
LVL 9

Expert Comment

by:masheik
ID: 34101249
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
 

Author Comment

by:jralexander137
ID: 34102874
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
 
LVL 53

Accepted Solution

by:
Infinity08 earned 2000 total points
ID: 34103291
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
 

Author Comment

by:jralexander137
ID: 34105742
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
 
LVL 53

Expert Comment

by:Infinity08
ID: 34106681
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
 

Author Comment

by:jralexander137
ID: 34107209
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
 

Author Comment

by:jralexander137
ID: 34107647
If you know of any websites or something that would help me that would be great.
0
 
LVL 53

Assisted Solution

by:Infinity08
Infinity08 earned 2000 total points
ID: 34109581
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
 
LVL 40

Expert Comment

by:evilrix
ID: 34824211
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question