LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   C compiler, assembler, architecture (https://www.linuxquestions.org/questions/linux-newbie-8/c-compiler-assembler-architecture-803145/)

tautvilis 04-20-2010 05:38 PM

C compiler, assembler, architecture
 
Hello, in class we started to study assembly and some questions came to my mind. While i couldnt find the answers by myself I had to ask them here. So I compiled a "hello, world" program written in C in my linux and then executed objdump -D file.out. In the book the same operation is executed with the same X86 processor(mine is also x86) and the machine instructions differ. Why and how can? Like jle, jmp mnemonics are totally diferent order, inc mnemonic isnt even used on my pc..I thought c compiler only compiles diferent binaries for diferent architectures: intel, powerpc, Spark..
Moreover, while every processor architecture has a different machine language instructions, it seems logical for me that then c compiler first compiles to mnemonics, which are then traduced to corresponding machine´s language instructions.
i really confused..
thanks!

giammy 04-21-2010 02:54 AM

Quote:

Originally Posted by tautvilis (Post 3941933)
Hello, in class we started to study assembly and some questions came to my mind. While i couldnt find the answers by myself I had to ask them here. So I compiled a "hello, world" program written in C in my linux and then executed objdump -D file.out. In the book the same operation is executed with the same X86 processor(mine is also x86) and the machine instructions differ. Why and how can?
...
thanks!

Hi,

Well, think about English: you can write different words to give the same meaning.

OR

The reason can be understand if you write down phrases with different words but same meaning.

OR

You can use different word to say the same thing.


A good exercise is to compile your program your program using different optimization flags: (in gcc -O, -O2 for example, but in the manual you find many flags)

A simple example (i do not know x86 assembly sufficiently to write code on the fly - but I hope you get the idea):

IF i < 7 is equal to IF i <= 6 (i is integer)

Coding is almost like writing ... you can use different styles, even writing assembly code :-)

bye
giammy

hda7 04-21-2010 12:22 PM

Quote:

it seems logical for me that then c compiler first compiles to mnemonics, which are then traduced to corresponding machine´s language instructions.
Different architectures generally have different instruction sets (and therefor a different set of mnemonics). GCC does compile to assembly mnemonics before assembling. You can use the -S option to give the unassembled mnemonics.


All times are GMT -5. The time now is 12:11 AM.