I was wondering if there's some special way to compile high-level code (preferably from c/c++ or java) to get the corresponding assembly code.
assuming you are using gcc, http://www.delorie.com/djgpp/v2faq/faq8%5F20.html tells you to gcc -O2 -S -c foo.c
look at the manual/doco for your compiler - i m sure there is an option to do it.
gcc can dump an assembly listing using -S switch - it will emit the assembly code to a file with a .s extension. For example, the following command:
gcc -O2 -S -c foo.c
will leave the generated assembly code on the file foo.s.
If you want to see the C code together with the assembly it was converted to, use a command line like this:
gcc -c -g -Wa,-a,-ad [other GCC options] foo.c > foo.lst
which will output the combined C/assembly listing to the file foo.lst.
Most compilers will support something similar to aid debugging the compiler itself. For Visual C++, see this guide.
Those languages are quite different in that C and C++ are normally compiled to machine code, whereas Java uses a virtual machine. You cannot sensibly compile Java to assembly language (if you want to see the machine code, use a debugger), but with C or C++ it should be quite easy, depending on your compiler. For example, when using gcc
, simply give it a -S
option and it will produce an assembly code file instead of the object code.
Many compilers come with the option of listing the generated assembly code. For example, gcc has the -S option, which will stop the compilation before assembling and leave you with assembly files.