Assemblers, compilers and interpreters
Computers will only understand instructions and data that are in binary form (machine code), so any code written in a high-level language (Python, C++) will need to be translated into machine codeComputer programming language, binary or hexadecimal instructions which the computer can respond to directly in order to be executed by the CPU.
There are three types of translator that can be used: a compilerA program that translates high-level programming languages into machine code., an interpreterA program that translates high-level programming languages into machine code. Programs can either be interpreted or compiled. and an assemblerTranslates assembly language into machine code.
Compiler
A compiler translates an entire program into machine code before execution. Discovering errors in the code can be difficult compared to interpreted languages, as all bugs are reported in an error report after the program has been compiled. An interpreter will discover errors as they come across them.
The machine code is saved and stored separately to the high-level code. Compilation is slow, but machine code can be executed quickly.
Java and C++ are examples of compiled programming languages.
Interpreter
Each time the program is run, an interpreter translates the code into machine code, instruction by instruction. The CPU executes each instruction before the interpreter moves on to translate the next instruction. Interpreted code will show an error as soon as it hits a problem, so it is easier to debug than compiled code.
An interpreter does not create an independent final set of source code – source code is created each time it runs. Interpreted code is slower to execute than compiled code.
Interpreter languages include JavaScript, PHP, Python and Ruby.
Assembler
An assembler translates assembly language into machine code. Assembly language is a low-level language written in mnemonics that closely reflects the operations of the CPU. For example, a common mnemonic is STA (store data to memory).
Each assembly language is particular to the computer and is not portable like high-level languages.
Assembly code can directly access hardware and is often used for writing device drivers and embedded system.
Assembly code is written directly for the CPU and hardware, and therefore code is very efficient as it does not need to be compiled or interpreted. Code operating systems are often programmed in assembly as they need to be very efficient.