compilers and assemblers

Hi guys I am reading a book called computer system architecture by M. Morris Mano

anyway I skipped to the chapter on programming,and it says that a compiler translates the code into machine language or ones and zeros but I thought to myself this isn't true because I thought the compiler translates the code into assembly?

and on a side not what is the job of an assembler? if the compiler translates code into assembly what does the assembler do? also when does the assemblers job take place? before the linker or after?

thanks


The compiler's end result is an executable file (or executable soup in the form of a library). Whether the "compiler" invokes an "assembler" in its processing or not won't change this, so you may be hitting an area where how the word compiler is used causing some confusion. Most refer to the compiler behind the IDE of visual studio, but that 'compiler' probably makes use of an assembler too under the hood. Its a level of detail thing, really -- most don't care if it uses and assembler or not, just like they don't care if it writes extra intermediate files or not.

Technically, yes, the compiler very likely (it does not have to, but most do) does convert to assembly first and invoke an assembler. I am fairly certain linkers deal with machine language code, but not 100%. You can google on it if you need to know.

Assemblers are just compilers for assembly language. It converts human readable text (assembly language) into actual cpu instructions (integer format, usually). CPU instructions are typically in the format of integers (these days, 64 bits wide) which is just going to look like, well, what you see in a hex editor if you open an executable file. Assembly looks like code.





Hello adam2016,

anyway I skipped to the chapter on programming,and it says that a compiler translates the code into machine language or ones and zeros but I thought to myself this isn't true because I thought the compiler translates the code into assembly?

I will try to build on what jonnin has said.

For the most part if you could look at the file it would be filled with "1"s and "0"s although this is generally look at as a hex value in base 16.

The first few bits of a are likely to contain an instruction like:
jmp 3E8
which means jump to an offset of "0xo0E8" (1000 decimal). The way the program works is that when loaded it is loaded at a given memory address and the program runs on an offset of this address. In this case jumping to an offset of 1000 may be where "main" starts.

So for the most part the compiler pulls everything together to basically finish with a file in machine code, or assembly language, that the computer can use.

and on a side not what is the job of an assembler? if the compiler translates code into assembly what does the assembler do? also when does the assemblers job take place? before the linker or after?


Your answer is in the middle of your question. If the compiler takes the C++ instructions that you wrote and writes assembly language instructions then the assembler takes the assembly language instructions and puts that into machine language, the "1"s and "0"s, that the computer and operating system can use.

There are more technical definitions, so I tried to make it simple.

Hope that helps,

Andy
Topic archived. No new replies allowed.