Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where do the compiler and assembler reside on a computer?

So I know the very basics, that a compiler turns source code into assembly code and an assembler turns assembly code into machine code. What I haven't been able to google properly though, is where are they actually located?

I'm assuming that the compiler is just somewhere on the hard drive since you can download compilers from the web and use them for various programming languages.

Is the assembler located on the hard drive, built into the operating system, or somewhere in the actual CPU? Is it possible to select a different assembler to use or do they come preinstalled into the hardware? Also is an assembler language specific like a compiler depending on how the assembly code originated, or is there only one assembler for an entire system?

like image 929
Austin Avatar asked Jun 16 '16 20:06

Austin


People also ask

What is compiler and assembler in computer?

Compiler converts the source code written by the programmer to a machine level language. Assembler converts the assembly code into the machine code. Compiler input source code. Assembler input assembly language code. It converts the whole code into machine language at a time.

Is the compiler a part of the computer hardware or software?

Detailed Solution. A compiler is a software program that translates computer code written in one programming language into another language. A compiler is used for programs that translate source code from a high-level programming language to a lower-level language.

How many compilers are there in a computer system?

There are over 50 compilers for C like ICC by Intel to GNU GCC by GNU Project. The focus of having multiple compilers is to optimize the compiled C code for specific hardware and software environments. This has lead to a vast number of compilers but some have been abandoned in the path.


1 Answers

You are overcomplicating this. A compiler takes text in some format and converts it, typically, to text in another format. Say for example a C compiler turns C into assembly. A compiler is just a program, nothing special about it just like your web browser is a program, the text editor you use for writing the programs is just a program, the command line/console if you use one is just a program. No magic.

An assembler is just a program that takes text in and typically outputs some form of binary file. There are many formats just like there are many binary formats for images and videos (bmp, jpg, png, gif, tiff, m4v, mpeg, etc). No magic, just a program that does a job like any of the ones listed above.

Same goes for the linker, it takes binary files in and typically outputs a binary file out.

These programs are, typically, like all other programs on your hard drive, or at least on a drive you have mounted and can access. Like the web browser and text editor, etc. Now to run them you need them "in the path" ideally or if part of some IDE then the IDE might not need them in the path it may know relative to itself where they are. Likewise the compiler which often calls the assembler and linker for you, might not need the path it may know/assume relative to where it is where they are. But they live on the file system like any other program/file but to execute them they need to be able to be found. And depending on the operating system and the installer for the toolchain there are often different choices and not one global rule.

There is no reason why you cant have as many different compilers and assemblers as you can fit on your filesystem, they are just programs like any other, so you have to find a place for them and have to have a way to run them. There is no reason to assume that any two compilers produce the same binary from the same source code, likewise there is no reason to assume that any assembler is able to assemble the output of any compiler. That is where the term toolchain comes from, a set of tools that link together in a chain, compiler outputs something the assembler in the toolchain knows how to deal with the assembler outputs something the linker knows how to deal with. You might have some cross compatibility among different toolchains/vendors, but that doesnt mean they have to that could either be by design, or dumb luck.

like image 190
old_timer Avatar answered Nov 15 '22 08:11

old_timer