I can't get through Compilers and Compiler Generators by PD Terry until I get through Art of Assembly first, and thats going to take weeks!
My question - do most compilers (not .net, but C, obective C, C++, etc.) generally, do they generate assembly and compile the assembly, or do they actually generate - binary? or Hex? and some examples.
Another example why its awesome having Beer and Sven around, nowhere else could I get this type of question answered
thanks in advance
-
-
I'd expect they go directly to binary. Assembly is really a 1:1 mapping with binary instructions, it just takes up more space being human readable.
-
Compiler article on Wikipedia
From a technical point of view, compilers translate from any language to any (other) language.
"Most compilers translate source code written in a high level language to object code or machine language that may be directly executed by a computer or a virtual machine"
-
machine language = binary?
Anyone around here ever translate assembly into binary?
-
Nata1 wrote:
machine language = binary?
Anyone around here ever translate assembly into binary?
With an assembler, yes. I think you'll find it rare that anyone actually writes programs using nothing but numbers these days. Assembly is at least symbolic and mnemonic, and translates fairly directly to machine code.
-
I'm totally obsessed with the HLA compiler (High Level Assembly) from the Art of Assembly book - it actually compiles assembly code for the MASM (windows) or GAS (Linux) - but I can't figure out where one would start writing a MASM or GAS!!!
Where do we go to figure that one out!!! -
Most now go directly to binary, generating an intermediate assembler file simply takes extra time due to I/O overhead. I'm fairly sure that Visual C++, when told to generate an assembly listing, actually generates it by disassembling the code it just generated. It fails if it can't find msdisxxx.dll, where xxx is a version number: v6 uses msdis110.dll, v7 (2002) uses msdis130.dll, v7.1 (2003) msdis140.dll and v8 (2005) msdis150.dll. The description of this file is 'Microsoft Disassembler'.
-
Nata1 wrote:
machine language = binary?
Anyone around here ever translate assembly into binary?
In school I did the reverse. I got to write a disassembler that looked at binary in memory and displayed opt codes and operands to the screen. After a few days of working on one of those you get to learn hex->binary and binary-> hex really well. Assembly is a literal translation from human readable (barely
) text to binary.
Oh...and the disassebler had to be written in assembly. It made for a good test case (can I disasseble my own program?). -
Mike that was awesome!!! thanks alot!
Now how the heck does it go directly to machine code for x processor? -
cool - so you actually turned Assembly into Binary and Binary into Assembly? Where did you start there?
And Where's Beer28 when I need'em? -
From a high level view, the compilation process is something like this:
1. Lex the source (i.e. find tokens, identifiers, keywords, constants)
2. Parse (make sure the program's syntax is correct)
3. From there many many phases can exist, such as symbol table building (to find variables that are used but not yet declared)
At this point the source code is in an Abstract Syntax Tree (AST) or some other intermediate language. It can go through many phases of intermediate languages, but basically its purpose is to provide a way to do optimizations and other things.
Once it does that, it would usually generate some type of assembly file, then the linker would link in library code. Then the actual binary would be generated.
*Disclaimer* I probably left out quite a bit. I typed this up pretty quickly. Someone else can chime in and fill in the blanks.
Compilers are the way of the future, especially with managed languages, and dual core processors. The hardware will rely more and more on software techniques to realize performance. -
Josh - that was Awesome - Exactly what I was looking for

-
More links can be found here.
-
fsfre, I just posted on that thread - one of the most awesome Channel9 threads BTW - but its nowhere to be seen. Why is that? Do these forums suck?
-
the Dragon compiler book?
Hey Beer - I'm racking up all the references possible - so I can create the Nata# compiler (just ripping off HLA with C# syntax)
I love this stuff! Thanks everyone! -
I'd venture to say "most" compilers go directly to binary, although it really depends on the language and environment. I used to do a lot of embedded programming with 8 bit CPUs, and some of the C compilers generated assembly files, then passed the assembly through a table driven cross-assembler for specific CPUs.
-
Nata1 wrote:the Dragon compiler book?
Compilers - Principles, Techniques and Tools by Aho, Sethi and Ullman
From the picture I think it's pretty obvious why it's called the dragon book.
It's a good book, covers all the essentials of compiler design. We used it at Uni for the
Compiler Construction course, which I took about three years back.
EDIT: The compiler I wrote for that course, a subset of the pascal language, didn't generate binary code, but MIPS assembly files that could be executed by the SPIM emulator. -
Nata1 wrote:
machine language = binary?
Anyone around here ever translate assembly into binary?
I wrote a Z80 assembler for the 8 bit Amstrad machines several years ago. As others have said, assembly and machine code basically have a 1:1 mapping so it's no more difficult to generate one rather than the other.
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.