Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does a compiler have an assembler too?

My understanding is that a compiler converts the high level language into machine code. I have a question as to whether a compiler(say VC++) in-turn uses an assembler too? I remember seeing assembly code, whenever there is a crash or something like that.

like image 720
Sam Avatar asked Jun 20 '10 17:06

Sam


People also ask

Do you need assembly to write a compiler?

TL;DR - if compiler and debugger writers are perfect you probably don't need assembler for application programming. However, your fundamental understanding of computing will not be complete. You will loose the ability to step outside the box.

What does a compiler contain?

A compiler is a special program that translates a programming language's source code into machine code, bytecode or another programming language. The source code is typically written in a high-level, human-readable language such as Java or C++.


1 Answers

It depends on the compiler; many compilers can compile to assembly. For instance, if you pass the '-S' flag to gcc, like:

gcc -S -o test.S test.c

That will output assembly for your test.c file into the file test.S which you can look at. (I recommend using -O0 if you're gonna be trying to read the assembly, because compiler optimizations in there will likely confuse the heck out of you).

Since you mentioned Visual C++ in your question, Paul Dixon points out below that Visual C++ uses the /FA flag to accomplish the same thing.

like image 166
Adrian Petrescu Avatar answered Oct 10 '22 14:10

Adrian Petrescu