How to converting the c++ code to assembly
Hi guys,
i really need help how to converting the c++ code to assembly. can anybody help me. for example this code #include <stdio.h> float average(float x, float y); int main() { float a, b, c; a = 1; b = 3; c = average(a, b); printf("The average of %f and %f is %f.\n", a, b, c); } float average(float x, float y) { float z; z = (x + y) / 2; /* The average */ return z; } i would really appreciate if anybody could help me convert to assembly language. thank and best regards. |
gcc -S source.cpp -o out.s
Does that do it? |
g++ -S source.cpp -o out.s
maybe this could be work if the gcc does not work.... |
'g++ source.cpp' produces a.out .
'./a.out' displays The average of 1.000000 and 3.000000 is 2.000000. And as shown in #2 and #3, the -o option allows you to choose any name for the produced object. .... |
Quote:
I can see few circumstances in which the direct answer to the question asked is directly all that helpful (except in a zen kind of sense, and that is somewhat indirect); is this related to homework? |
Quote:
|
Hi All,
But this gcc command where I can writing, because For the first time I use it. and what you mean with 'out.s'. thanks |
Open a terminal, navigate to the location of your source file, and then issue the command. The file produced (out.s or source.s) will contain the assembly code (try cat out.s).
@ErV: Thank you, you are right, but I believe specifying the output file is a good habit (for instance if you say gcc source.c it will output to a.out), and I see no harm in using it. Cheers:) |
Hi All,
thanks for your replay, but I still do not know how to use the gcc command from a terminal or how to run the terminal from where running, and what is the exactly syntax of gcc command. e.g #gcc -S progectname.cpp -o outputfile.s (how to write this in a terminal??) the outputfile include the assembly code. thanks |
Quote:
Quote:
Quote:
|
Nice piece of c++ code, but it will only produce
an executable with 'c++' = 'g++' , not with 'gcc -S' |
Hi All,
you can give me the gcc command for windows because i don't have it. thanks |
Quote:
I'm going to re-iterate that assembler is assembler for a particular processor architecture or maybe even more specific than that, although, say, any arm assembler variant ought to be comprehensible to anyone who understands other arm assembler formats - after all, you do not seem to be trying to execute anything. So without specifying the architecture there cannot be a single answer to your question; answers given may be totally useless to you if your understanding of other architectures is not good enough. |
Quote:
In your other thread, you have not replied to any of the recent comments. I will recommend that this be closed. |
Quote:
I am not sure if you can use 1 "start" 2 cmd 3 "find your ELF(in windows it should be a file like this abc.exe,and lets' assume the ELF file is named abc.exe) and cd(change directory) in that "Directory" " 4 use debug abc.exe. 5 type u. now,look,does that you want ? if it is now,maybe you should add another information to it. like type u 00 /100/someother data ; specify the lines' that your program start at. (well,I did not use debug for a long time,and I can not remember it clearly,maybe I got some mistakes,you should go and google some information about "debug command" ,then do it .) |
Quote:
|
"This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game." |
Quote:
|
All times are GMT -5. The time now is 07:48 PM. |