Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Chandra_V_
Beginner
78 Views

Basic doubt on Assembly format (updated)

Dear All,

I am new to assembly language. Using, GCC on Windows 7 with Mingw. Using following command, using source file Hello.c, 

got the Disassembley  on the Hello_asm.txt ( can see the assembly content..believe it is in Intel format).

objdump -M intel -S -d Hello.o >Hello_asm.txt

Fine. Now, another secnario,   if the use the Intel C++ compiler on my Windows 7 PC, Without  Visual studio environment, compile Hello.c and get the  Assembly file.. believe it will created with .asm  ( Hello.asm.).  My doubt :  Hello.asm ( Intel)  and Hello_asm.txt (GCC) will have same assembly language content for the x86  platform/Windows. Irrespective of whether an exe  file created or not  (from Obj file or  assembler)

Please advise. Am i missing any info.

Cheers!

Chandra 

0 Kudos
7 Replies
Viet_H_Intel
Moderator
78 Views

 

Hi Chandra,

If you compared instructions to instructions, then the 2 compilers might not generate the same asm, but it should run. Also, you can mix-match objects compiled with Intel compiler with MS on Windows or Gnu on Linux. 

Regards,

Viet Hoang

 

 

 

Chandra_V_
Beginner
78 Views

Dear Viet Hoang,

Got your point. Will look into.. and update here.

Thanks a lot.

-cheers! chandra

mecej4
Black Belt
78 Views

Windows and Linux use different conventions for passing arguments in registers to functions, and this difference can make the two assembler files substantially different. There are utilities available for porting assembler files; see, for example, http://www.agner.org/optimize/#objconv .

jimdempseyatthecove
Black Belt
78 Views

Additionally, Linux systems often require code to be written in Position Independent Code (PIC) format, whereas Windows does not (code relative to the VM's location 0).

Jim Dempsey

Chandra_V_
Beginner
78 Views

Thanks all for replies. Understand, Linux and Windows are different.At the moment, i am comparing  GCC (Windows/MINGW/GCC)  and

Intel (Windows - Intel C/C++ compiler). Will update soon.

Thanks. Cheers!

chandra

 

Chandra_V_
Beginner
78 Views

Dear All, 

i am try to explore from 2 type of assembly output for our project.

GCC (Windows/MINGW/GCC)  / gcc -S -masm = intel hello.c

Intel  (Windows - Intel C/C++ compiler - IA32 Visual studio environment )  / icl - c -S -o hello.s hello.c

Objective: Our project (pure 32 bit C application. ) is at beginning stage. It should run on cross platform with minimum effort  on Windows, MAC OS, Linux (ARM), Android (ARM). The final executable should  converted from assembly (after some optimization)..

1 ) So, in this how Intel C/C++ compiler (output assembly) will be better than GCC.  (AT & T syntax vs Intel syntax)

2 ) Believe, Intel do not have ARM compiler, is there any method to convert from Intel syntax to  ARM (like Raspberry Pi)

3) Seeing from simple - Hello World program... the Intel syntax gives more verbose which will helpful to understand assembly. (attached both files). 

(the question slight become complex than originally). So, at the end, we have to choose either GCC or Intel.Any thoughts useful :)

Cheers!

chandra

jimdempseyatthecove
Black Belt
78 Views

The C source file can be written to be compiled on, or targeted to, a specific platform. Some of your source files may require conditional compilation directives to enable/disable sections of code and/or include files. The generated executable generally will not be portable either due to C Runtime differences or Instruction Set architecture differences (IA32  verses ARM). 

As you can see from your two text files the GCC built program is using its _puts CRTL function, whereas the Intel compiler is using ___stdio_common_vfprintf (in addition to making calls to additional functions).

To aid in making "transportable code", I recommend renaming your "main" to "my_main", then creating a new main that simply calls my_main with the same arguments. This will isolate any system dependent initialization (and shutdown) code.

You can also think if it is appropriate to do this with other CRTL functions, such as printf.

Jim Dempsey

Reply