ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
You should specify the processor architecture, if you want something that you can work with.
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?
It is actually "gcc -S source.c". "-o out.s" isn't necessary at all, because gcc will create source.s automatically for each file. See "man gcc" for more info about -S switch.
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
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.
you can give me the gcc command for windows because i don't have it.
thanks
Are you saying you don't have gcc (well, get it, then), that you don't understand what to type on the command line (in spite of the fact that you have been told several times) or that you don't have windows (not what I'd call a problem, but maybe a fact all the same)?
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.
you can give me the gcc command for windows because i don't have it.
thanks
You make me ...
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 .)
Last edited by twwwater; 12-27-2008 at 07:48 PM.
Reason: Maybe I got wrong...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.