Compilers, interpreters and assemblers
Any program written in a high-level languageAlso known as high level language. This is a computer programming language used to write programs. High-level languages need to be translated into machine code through a compiler, interpreter or assembler. is known as source codeThe code behind a computer program, written in a programming language.. However, computers cannot understand source code. Before it can be run, source code must first be translated into a form which a computer understands - this form is called object codeCode that can be understood by a processor..
A translatorProgram translators convert program code into machine code to be executed by the CPU. There are three types of translator: interpreter, compiler and assembler. is a programSequences of instructions for a computer. that converts source code into object code. Generally, there are three types of translator:
- compilerA program that translates high-level programming languages into machine code.
- interpreterA program that translates high-level programming languages into machine code. Programs can either be interpreted or compiled.
- assemblerA program that translates assembly languages into machine code.
Compilers
A compiler takes the source code as a whole and translates it into object code all in one go. Once converted, the object code can be run at any time. This process is called compilationThe process of translating source code into object code all in one go. The program can then be executed as a whole..
All of the object files used in a program must be combined before the program can be run. This is done using a linker tool, which takes one or more objects and groups them into a single executableA file that, when run, starts a program. or a libraryIn computing, a collection of functions stored in a separate file..
Compilers have several advantages:
- Compiled programs run quickly since they have already been translated.
- A compiled program can be supplied as an executable file. An executable file is a file that is ready to run. Since an executable file cannot be easily modified, programmers prefer to supply executables rather than source code.
- Compilers optimiseTo make a program more efficient. A program can be optimised to run quicker, or to take up less memory. code. Optimised code can run quicker and take up less memoryThe part of a computer that stores data. space.
Compilers have several disadvantages:
- Because the source code is translated as a whole, there must be enough memory space to hold the source code, the compiler and the generated object code. There also needs to be temporary working space for the compiler to perform the translation. Modern systems either have enough memory or use virtual memoryA section of a computer storage drive which is temporarily used as RAM. to hold all the data.
- Compilers do not usually spot errors - the program has to be compiled and run before errors are encountered. This makes it harder to see where the errors lie.
- The source code must be recompiled every time the programmer changes the program.
- Source code compiled on one platform will not run on another - the object code is specific to the CPU/processorCentral processing unit - the brain of the computer that processes program instructions. architecture.
Interpreters
An interpreter translates source code into object code one instructionA single action that can be performed by a computer processor. at a time. It is similar to a human translator translating what a person says into another language, sentence by sentence. The resulting object code is then executed immediately. The process is called interpretationThe process of translating source code into machine code one instruction at a time. Each instruction is then executed..
Interpreters have several advantages:
- Instructions are executed as soon as they are translated.
- Since instructions are executed once translated, they are not stored for later use. As a result, interpreters require less available memory.
- Errors can be spotted quickly. Once an error is found, the program stops running and the user is notified at which part of the program the interpretation has failed. This makes interpreters extremely useful when developing programs.
Interpreters also have several disadvantages:
- Interpreted programs run more slowly. The processor has to wait for each instruction to be translated before it can be executed.
- Additionally, the program has to be translated every time it is run.
- Interpreters do not produce an executable file that can be distributed. As a result, the source code program has to be supplied and this could be modified without permission.
- Interpreters do not optimise code - the translated code is executed as it is.
Assemblers
Assemblers are a third type of translator. The purpose of an assembler is to translate assembly languageA low-level programming language closely related to machine language. Also called assembly code. into object code. Whereas compilers and interpreters generate many machine codeAlso called object-code, this is low-level code that represents how computer hardware and CPUs understand instructions. It is represented by either binary or hexadecimal numbers. instructions for each high-level instruction, assemblers create one machine code instruction for each assembly instruction.
Loader
A loader is a piece of softwareThe programs, applications and data in a computer system. Any parts of a computer system that aren't physical. that is responsible for loading executable files into memory to enable the central processing unit (CPU) to run them. It calculates the size of a program and dedicates enough memory space for it to run efficiently.
More guides on this topic
- The CPU - Eduqas
- Primary storage - Eduqas
- Secondary storage and embedded systems - Eduqas
- Networks - Eduqas
- Internet and cybersecurity - Eduqas
- Data representation - Eduqas
- Storage and data organisation - Eduqas
- Operating systems - Eduqas
- Principles of programming - Eduqas
- Algorithms - Eduqas
- Sorting, searching and validation - Eduqas
- Impacts of digital technology on wider society - Eduqas