Results 1 to 4 of 4
Could I get some separation on the two of what makes them different? What part of a compiler changes the code from assembly to machine?
Thanks in advance!...
- 05-19-2011 #1
Assemblers and Compilers Definition of
Could I get some separation on the two of what makes them different? What part of a compiler changes the code from assembly to machine?
Thanks in advance!
- 05-19-2011 #2
Assembly and machine code are pretty closely interrelated. I'm not sure of the exact definition, but I tend to think of them this way:
Assembly language is a very simple, human-readable programming language that maps 1-to-1 to machine language. The following is an example of the MIPS assembly language:
This is a relatively simple program, and it may not make much sense if you don't know assembly language, but it is quite understandable to someone who understands assembly language, particularly someone who knows MIPS.Code:li $s0, 5 ; Set the $s0 register = 5 addi $s1, $s0, 10 ; Add 10 to the $s0 register and store the result in $s1 move $a0, $s1 ; Copy the value in $s1 into the $a0 register jal foo ; Call the foo function
However, if I run this code through an assembler, it might produce the following file:
These two files say the same thing, and it is well documented how to turn the commandCode:01111100001000000000000000000000 01110110000000010000000000000101 00100010001100000000000000001010 00100000100100010000000000000000 00001100010101011100000101000000
intoCode:$addi $s1, $s0, 10
There is also only one "machine code" that the assembly can be turned into, and the assembly can only represent one command. This machine code is easier for the computer to understand, but it is obviously much harder for a human.Code:00100010001100000000000000001010
So that's what I consider to be the difference between "assembly language" and "machine language".
As for the compiler, it depends. If the original code was written in assembly language, you can use an assembler (such as spim for MIPS) to simply translate the code and execute it. It's very easy.
If the original code was written in a more complicated language such as C, the compiler has a number of steps. Once the compiler understands the C code, it will eventually translate the code into something called an "intermediate representation". The intermediate representation is essentially an abstract assembly language. This intermediate representation, instead of using specific registers, will likely refer simply to fake registers, where every variable uses its own register.
Later, the intermediate representation will be converted to the target assembly language, still with the fake registers. Finally, the compiler will eventually do "register allocation", where it figures out conflicts in the various stages of the program and assigns real registers to each of the fake ones.
This is a very brief overview of how compilers work, and whole college courses are dedicated to the subject of compilers. If you're seriously interested in compilers, I used this textbook to learn about them:
Amazon.com: Modern Compiler Implementation in ML (9780521607643): Andrew W. Appel: Books
This book is also very popular:
Amazon.com: Compilers: Principles, Techniques, and Tools (2nd Edition) (9780321486813): Alfred V. Aho, Monica S. Lam, Ravi Sethi, Jeffrey D. Ullman: BooksDISTRO=Arch
Registered Linux User #388732
- 05-19-2011 #3
Thanks for the great reply!
I seem to be learning more about Linux by digging into this type of subject. I'm reading about linkers and loaders right now. Thanks for the great response and the tip on the book!
- 05-19-2011 #4Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
Wikipedia is very useful for factual information of this kind, for example:
Assembly language - Wikipedia, the free encyclopedia
High-level programming language - Wikipedia, the free encyclopedia
and links therein ... cheers, drlWelcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )


Reply With Quote