LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How to convert this c++ code into assembly? (https://www.linuxquestions.org/questions/programming-9/how-to-convert-this-c-code-into-assembly-4175451066/)

falcan 02-21-2013 01:51 AM

How to convert this c++ code into assembly?
 
for (a=0; a<=y; a++)
for (b=0; b<=y/2; b++)
for (c=0; c<=y/3; c++)
if ((a + 2*b + 3*c) ==y)
count++;

millgates 02-21-2013 02:00 AM

Have you tried using a compiler?

Code:

g++ -S file.cpp

falcan 02-21-2013 08:27 AM

thanks
 
i dont know how to use it...can pls post the assembly code..it is urgent i need it

grail 02-21-2013 08:29 AM

hmmm ... urgent to you perhaps which now makes it sound and look like a homework question.

If not homework, please explain what you are trying to do and where you are stuck?

Note: Answers not excepted will be, turn code into assembler and don't know how.

TKH 02-21-2013 03:34 PM

gcc -S <input file> -o <output file>

colucix 02-21-2013 05:43 PM

Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.

Sergei Steshenko 02-22-2013 04:53 AM

Quote:

Originally Posted by falcan (Post 4896491)
for (a=0; a<=y; a++)
for (b=0; b<=y/2; b++)
for (c=0; c<=y/3; c++)
if ((a + 2*b + 3*c) ==y)
count++;

Are you sure this is a valid C++ code ? Have you tried to compile it as C++ code first ?

psionl0 02-22-2013 08:41 PM

Quote:

Originally Posted by falcan (Post 4896491)
for (a=0; a<=y; a++)
for (b=0; b<=y/2; b++)
for (c=0; c<=y/3; c++)
if ((a + 2*b + 3*c) ==y)
count++;

Is this a subroutine or a snippet of main code?
Is y a global variable? Or is y a parameter that was pushed on the stack? Or is y a parameter stored in the EAX register when the code snippet was executed?

Is count a global variable or is it something to be returned on the stack or EAX register? Does count need to be initialized?

Maybe y and count are addresses that were pushed on the stack before this code snippet was run?
Maybe y and count are addresses that were stored in the EAX and EBX registers before this code snippet was run?

BTW If you use CODE tags the program fragment will display the way you intended.


All times are GMT -5. The time now is 03:05 AM.