In general, compiler is a computer program that reads a program written in one language, which is called the source language, and translates it in to another language, which is called the target language. Traditionally, source language is a high level language such as C++ and target language is a low level language such as Assembly language. However, there are compilers that can convert a source program written in Assembly language and convert it to machine code or object code. Assemblers are such tools. On the other hand, Interpreters are tools that execute instructions written in some programming language. Interpreter can either directly execute high level source code or translate them to intermediate code and then interpret it or execute precompiled code.
What is an Assembler?
Assembler is software or a tool that translates Assembly language to machine code. So, an assembler is a type of a compiler and the source code is written in Assembly language. Assembly is a human readable language but it typically has a one to one relationship with the corresponding machine code. Therefore an assembler is said to perform isomorphic (one to one mapping) translation. Advanced assemblers provide additional features that support program development and debugging processes. For example, the type of assemblers called macro assemblers provides a macro facility.
What is an Interpreter?
An interpreter is a computer program or a tool that executes programming instructions. An interpreter may either execute the source code directly or converts the source to an intermediate code and execute it directly or execute precompiled code produced by a compiler (some interpreter systems include a compiler for this task). Languages like Perl, Python, MATLAB and Ruby are examples of programming languages that use an intermediate code. UCSD Pascal interprets a precompiled code. Languages like Java, BASIC and Samlltalk first compile the source to an intermediate code called bytecode and then interpret it.
What is the difference between an Assembler and an Interpreter?
An assembler can be considered a special type of compiler, which only translates Assembly language to machine code. Interpreters are tools that execute instruction written in some language. Interpreter systems may include a compiler to pre-compile code before interpretation, but an interpreter cannot be called a special type of a compiler. Assemblers produce an object code, which might have to be linked using linker programs in order to run on a machine, but most interpreters can complete the execution of a program by themselves. An assembler will typically do a one to one translation, but this is not true for most interpreters. Because Assembly language has a one to one mapping with machine code, an assembler may be used for producing code that runs very efficiently for occasions in which performance is very important (for e.g. graphics engines, embedded systems with limited hardware resources compared to a personal computer like microwaves, washing machines, etc.). On the other hand, interpreters are used when you need high portability. For example, the same Java bytecode can be run on different platforms by using the appropriate interpreter (JVM).