C++ to MIPS Conversion

i'm working on a mips conversion

Page 1 of 1

3 Replies - 8153 Views - Last Post: 25 October 2009 - 02:52 PM Rate Topic: -----

#1 hazezoos  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 11
  • Joined: 24-September 08

C++ to MIPS Conversion

Post icon  Posted 23 October 2008 - 03:22 PM

I'm am trying to convert a c++ for loop into a mips for loop. this is what i have so far....

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:

Is This A Good Question/Topic? 0
  • +

Replies To: C++ to MIPS Conversion

#2 kdoztekin  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 20-October 09

Re: C++ to MIPS Conversion

Posted 20 October 2009 - 01:49 PM

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 October 2009 - 01:50 PM

Was This Post Helpful? 0
  • +
  • -

#3 wildgoose  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 67
  • View blog
  • Posts: 468
  • Joined: 29-June 09

Re: C++ to MIPS Conversion

Posted 23 October 2009 - 10:47 AM

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
Was This Post Helpful? 0
  • +
  • -

#4 chls89  Icon User is offline

  • New D.I.C Head

Reputation: 12
  • View blog
  • Posts: 47
  • Joined: 19-September 09

Re: C++ to MIPS Conversion

Posted 25 October 2009 - 02:52 PM

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:
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 October 2009 - 02:53 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1