Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
38 Views

Assembly Listings with -fcode-asm

Jump to solution
Hi,

I tried to create an assembly listing with code annotations. I tried to do it on a windows and a linux machine. From my compile runs i got several outputs:

Windows:
"icl /C /Fa test.cpp" => asm-file
"icl /C /Fa /FAc test.cpp" => cod-file

Linux:
"icc -S test.cpp" => s-file
"icc -S -fcode-asm test.cpp" => cod.file


asm-file and s-file have different formats. If I got this correct, s-file from Linux-Version is in Intel-format. The same is true for cod-file from Windows and cod-file from Linux. cod-file on Linux is in Intel-format.

And now to my question:
On the windows machine i see in the cod-file the machine code annotations. E.g:
.B1.1: ; Preds .B1.0
00000 8b 54 24 04 mov edx, DWORD PTR [4+esp] ;D:\\cotest\\test.cpp:12.7
00004 89 11 mov DWORD PTR [ecx], edx ;D:\\cotest\\test.cpp:12.28

On the linux machine i see no machine code annotations, only the filename is now provided. E.g:
..B1.1: # Preds ..B1.0
movl 4(%esp), %edx #test.cpp:12.7
movl 8(%esp), %eax #test.cpp:12.7

First Question: Am I doing something wrong or why are the machine code annotations missing on my linux-machine?
Second Question: Is there an icc-option like the gcc-option -masm=[intel|att]?

Thank you for your help.

Some more details:
* icc V 11.1 20100414.

* test.cpp:
class Test {
public:
Test(int i);
int testMethod(int a, int b);
private:
int m_int;
};
Test::Test(int i) : m_int(i) {}
int Test::testMethod(int a, int b) { return a + b + m_int;}


0 Kudos

Accepted Solutions
Highlighted
Black Belt
38 Views
"If I got this correct, s-file from Linux-Version is in Intel-format" -- No, .s files are in AT&T (adopted by GNU) format.

There is a utility for converting .o/.obj files, called objconv.

You can run the GNU assembler ('as' on Linux) with the -a option to produce a listing with code bytes. With compilers that allow you to pass options to the assembler, you can use something resembling -Wa,.

View solution in original post

0 Kudos
6 Replies
Highlighted
Black Belt
39 Views
"If I got this correct, s-file from Linux-Version is in Intel-format" -- No, .s files are in AT&T (adopted by GNU) format.

There is a utility for converting .o/.obj files, called objconv.

You can run the GNU assembler ('as' on Linux) with the -a option to produce a listing with code bytes. With compilers that allow you to pass options to the assembler, you can use something resembling -Wa,.

View solution in original post

0 Kudos
Highlighted
Beginner
38 Views
Thank you, mecej4!

Your hints helped me solving my problem for now. I can do the job on linux by using some different tools during compilation.

Still I am confused about the output from icc on my linux machine with the "icc -S -fcode-asm ...". I expected another information than only giving me a filename in the comment. objconv (and also the windows Version icl) gives me what I expected but I prefer working with icc on linux.

Linux: "icc -S ..." gives me:
addl 8(%esp), %eax #10.49
addl 12(%esp), %eax #10.53

Linux: "icc -S -fcode-asm" gives me:
addl 8(%esp), %eax #test.cpp:10.49
addl 12(%esp), %eax #test.cpp:10.53

Windows: "icc -S -fcode-asm" gives me:
00002 03 44 24 04 add eax, DWORD PTR [4+esp] ;D:\cotest\test.cpp:15.49
00006 03 44 24 08 add eax, DWORD PTR [8+esp] ;D:\cotest\test.cpp:15.53




0 Kudos
Highlighted
Black Belt
38 Views
Why does one have to go through an extra step to obtain a listing with code bytes included? Because many compilers directly produce an object file (in the proper format for the platform, such as ELF, COFF, OBJ, etc.) and do not use an assembly step at all.

With such compilers, if you ask for an assembly listing, they may have to perform additional steps to produce one for you, and the listing may not be exactly the same as what you obtain by running a disassembler (such as objdump -d ) on the .o file.
0 Kudos
Highlighted
38 Views
The asm option is used to produce an assembly source file (one you can modify and then assemble using the dialect of the assembly source). Additional options are available to have the compiler perform the assembly and then emit an assembly listing file (with or without .c/.cpp source embedded as comments).

Note, other than for "no optimization" trying to follow embedded source comments is problematic as statements are rearranged, merged, unrolled, and/or eliminated.

Jim


0 Kudos
Highlighted
Employee
38 Views
Hi,
Jim has given you the correct response (thanks Jim). Yes, icc will produce the assembly file with -fcode-asm that will also contain source annotations to help understand the code in detail....
-regards,
Kittur
0 Kudos
Highlighted
Beginner
38 Views
Hi,

I think I understand things better now ...

Thanks for your help.

mettex
0 Kudos