programming language translators Flashcards
Translating assembly code
Assembly language is translated into machine code by a program called an assembler
Typically, one assembly code instruction is translated into one machine code instruction
Source code
The assembly code program is the input to the assembler
This is known as the source code
object code
The output is the machine code instructions produced by the assembler, called the object code
The object code can be saved and run whenever needed
Uses of assembly code
Assembly code is used when a program needs to execute as fast as possible, occupy as little space as possible or manipulate individual bits and bytes
Typical uses include embedded systems, real-time systems, sensors, mobile phones, device drivers and interrupt handler
Compilers
A compiler is a program that translates a high-level language such as Visual Basic or Delphi into object code
The compilation process
A compiler is a complex program which has several phases
lexical
syntactic
semantic
It produces intermediate code, optimises it, then generates the machine code
It will not generate the machine code it there are any errors in the program
Errors detected by the compiler
The compiler will find errors such as syntax errors or missing subroutines
When all errors of this kind have been corrected, the compiler will produce relocatable code, since it does not know the absolute addresses where the object code will be loaded
Advantages of a compiler
Once a program has been compiled, the object code can be distributed and the compiler is not needed to run the program
The object code runs faster than interpreted code
The object code is more secure, as machine code cannot easily be read and copied by someone wishing to modify the code and sell it as their own product
interpreters
The third type of translator is an interpreter
An interpreter translates high-level instructions into an intermediate form, which it then executes
No object code is produced
Advantages of an interpreter
An interpreter is useful in education
It is useful during development when a programmer may want to test a small piece of code
Both compilers and interpreters are available for most high-level languages
Bytecode
Some compilers such as the Java compiler compile the source code into an intermediate form known as bytecode