School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 307,118 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,982 people online right now. Registration is fast and FREE... Join Now!




C++ to MIPS Conversion

 

C++ to MIPS Conversion, i'm working on a mips conversion

hazezoos

23 Oct, 2008 - 02:22 PM
Post #1

New D.I.C Head
*

Joined: 24 Sep, 2008
Posts: 10



Thanked: 1 times
My Contributions
I'm am trying to convert a c++ for loop into a mips for loop. this is what i have so far....

CODE

int n = prompt;
double m = n/2;
sum = 1;
for (int i = 2; i <= m; i++)
  if (div(i,n))
    sum += i;
  if (sum == n)
    return 1;
  else
    return 0;


this is what i have on the conversion so far, help me if i am wrong.

move $s0, $zero
for1tst:slt $t0, $s0, $a1
beq $t0, $zero, exit1
bne $s3, $s4, nxline
nxline: bne $s5, $s6
addi $s0, $s0, 1
j for1tst
exit1:

User is offlineProfile CardPM
+Quote Post


kdoztekin

RE: C++ To MIPS Conversion

20 Oct, 2009 - 12:49 PM
Post #2

New D.I.C Head
*

Joined: 20 Oct, 2009
Posts: 1

int i;
void set_array(int num){
int array[10];
for(i = 0; i < 10; i++){
array[i] = compare( num, i ); }
}
int compare( int a, int b ){
if(sub( a, b ) >= 0)
return 1;
else
return 0;
}
int sub(int a, int b ){
return a-b;
}

I need help are there anybody to convert this c code to MIPS ????

This post has been edited by kdoztekin: 20 Oct, 2009 - 12:50 PM
User is offlineProfile CardPM
+Quote Post

wildgoose

RE: C++ To MIPS Conversion

23 Oct, 2009 - 09:47 AM
Post #3

D.I.C Regular
Group Icon

Joined: 29 Jun, 2009
Posts: 430



Thanked: 56 times
Dream Kudos: 25
Expert In: Assembly,C,C++

My Contributions
Both of you need to get proper functioning C code first, before even thinking about converting to assembly code!

integer to double float. And looped integer compared todouble?

setting an integer array with comparisons that go out of scope when function returns

User is online!Profile CardPM
+Quote Post

chls89

RE: C++ To MIPS Conversion

25 Oct, 2009 - 01:52 PM
Post #4

New D.I.C Head
*

Joined: 19 Sep, 2009
Posts: 11

CODE

move $s0, $zero
for1tst:slt $t0, $s0, $a1
beq $t0, $zero, exit1
bne $s3, $s4, nxline
nxline: bne $s5, $s6
addi $s0, $s0, 1
j for1tst
exit1:


It would be very helpful of you to comment which variables in assembly correspond to your C variables. This is a big problem with assembly -- very, very hard to read by someone other than the author. For now I will point out one thing that I saw - I didn't look at it too closely, I didn't want to decipher corresponding variables. Anyway, for:
CODE

bne $s3, $s4, nxline
nxline: bne $s5, $s6


If $s3 does not equal $s4, you jump to "nxline". Otherwise, you continue executing. However the next line to be executed is "nxline" so the bne there does nothing.


This post has been edited by chls89: 25 Oct, 2009 - 01:53 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 01:36PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month