LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-20-2010, 05:38 PM   #1
tautvilis
LQ Newbie
 
Registered: Apr 2010
Posts: 5

Rep: Reputation: 0
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!
 
Old 04-21-2010, 02:54 AM   #2
giammy
Member
 
Registered: Feb 2010
Posts: 36

Rep: Reputation: 20
Quote:
Originally Posted by tautvilis View Post
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
 
Old 04-21-2010, 12:22 PM   #3
hda7
Member
 
Registered: May 2009
Distribution: Debian wheezy
Posts: 252

Rep: Reputation: 31
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Assembler samjkd General 7 03-14-2005 01:52 PM
Assembler Firari Programming 9 12-10-2004 02:26 PM
assembler usr Programming 2 11-15-2003 05:15 PM
assembler tda Programming 4 08-21-2002 02:54 AM
Need an Assembler ChimpFace9000 Programming 1 07-18-2001 09:36 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration