Avatar of jralexander137
jralexander137
 asked on

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

Editors IDEsAssemblyC

Avatar of undefined
Last Comment
evilrix

8/22/2022 - Mon
Infinity08

I assume that this question is superseded by your other question (https://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).
Infinity08

(or better yet, you can delete it yourself)
Infinity08

Since it seems you decided to delete the other question instead, I'll re-post my response here :
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
SOLUTION
Infinity08

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
masheik

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
jralexander137

ASKER
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?
ASKER CERTIFIED SOLUTION
Infinity08

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
jralexander137

ASKER
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?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Infinity08

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 ?
jralexander137

ASKER
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.
jralexander137

ASKER
If you know of any websites or something that would help me that would be great.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
SOLUTION
Infinity08

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
evilrix

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.