what is difference between compiler and assembler?(
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
what is difference between compiler and assembler?(
Hi Friends,
while reading book on operating system I came across terms Assembler and Compiler, I read about them and I ended up in bigger confusion every time I read about these two, many posts and explanation on internet state that Assembler/Compiler translates source code into object-core which can be then executed, if what i've understood here is correct then there are some questions I have for which I was not able to find any good explanation.
Questions/Doubts
*) If what I've understood is correct then why two different programs?(only difference I can see is assembler can convert only assembly language where as compiler can do more of such languages)
*) As per book I have there is hierarchy of how program is executed I will try to write it down in short.
[High Level Language Program] -> (compiler) -> [Assembly language program] -> (Assembler) -> [Object Module] + [Object Library Module] -> (Linker) -> [Executable Machine language Program] -> (Loader) -> [Memory]
( I have created similar digram and attached to this post)
well problem with hierarchy is if both assembler and compiler are doing about the same job then why is compiler pointing to Assembler, according to me any one of two should be there in picture.
why did author keep compiler on the top of hierarchy? why not assembler?
does it means that compiler converts source code into assembly code and passes it to assembler then assembler converts it further to machine code (binary)?
Although this post may not relate specifically to Linux but is related to operating system, I posted this questions here expecting there would be some one around who might have better under understanding about operating system and it's components in general.
Assembly is a type of programming language where there's a one-to-one relation between the commands and the underlying machine code instructions. Assembly is simply a human-readable representation of the actual CPU codes, and converting an assembly language program into executable code is a relatively simple matter of converting each assembly mnemonic into the corresponding binary code.
(Yes, this is somewhat simplified, as most assemblers can expand macros and convert labels into addresses, but the main point still stands.)
A compiler, on the other hand, converts program code written in a high-level language into something the CPU can execute. Unlike assembly, a high-level language can contain abstractions like variables and functions, which really don't exist at the assembly/machine code level.
When a compiler translates a program written in a language like C into machine code, it may convert it into an assembly program and let an assembler handle the final conversion into an executable file.
One of the most common assemblers is the Microsoft Assembly (macro assembly) MASM. On their site they quote this.
"The Microsoft Macro Assembler 8.0 (MASM) is a tool that consumes x86 assembly language programs and generates corresponding binaries. Assembly language programs built with MASM can be edited and debugged using Visual C++ 2005 Express Edition. This installation requires the Visual C++ 2005 Express Edition to be installed on the computer." http://www.microsoft.com/en-us/downl...190a24fa6=True
This differs from a compiler where a different level of code is used as base.
If I were to have been in charge of Linux from the start, I'd have made it all in assembly.
Try compiling using the gcc '-save-temps' and you'll see that it generates a .s file which contains assembly code. If you wanted to you could use this generated assembly as is and it will work. You can also include global functions defined there in your C programs by making a function prototype defined as extern and adding the .s file to the gcc command line when compiling.
Yes, gcc passes the code to the 'as' assembler. It is usually in the same package as 'ld' which is the linker. Both of these are needed to create programs.
Not really, you could cross compile for a specific architecture. I would program for a Z80 on a x86 platform. Done all the time.
Hope this helps.
Have fun & enjoy!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.