Solved

Convert from C to MIPS

Posted on 2010-11-09
14
1,334 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
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
 
LVL 53

Assisted Solution

by:Infinity08
Infinity08 earned 500 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 53

Accepted Solution

by:
Infinity08 earned 500 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 500 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now