Language Translators Part 1
Language Translators Part 1
Key terms
Translator – the systems software used to translate Interpreter – a computer program that analyses and
a source program written in any language other than executes a program written in a high-level language line
machine code. by line.
Compiler – a computer program that translates a Prettyprinting – the practice of displaying or printing
source program written in a high-level language to well set out and formatted source code, making it
machine code or p-code, object code. easier to read and understand.
149
Assemblers
Programs written in assembly language are translated into machine code by
an assembler program. Assemblers either store the program directly in main
memory, ready for execution, as it is translated, or they store the translated
program on a storage medium to be used later. If stored for later use, then
a loader program is also needed to load the stored translated program into
main memory before it can be executed. The stored translated program can be
executed many times without being re-translated.
Every different type of computer/chip has its own machine code and assembly
language. For example, MASM is an assembler that is used for the X86 family
of chips, while PIC and GENIE are used for microcontrollers. Assembly language
programs are machine dependent; they are not portable from one type of
computer/chip to another.
Here is a short sample PIC assembly program:
movlw B’00000000’
tris PORTB
EXTENSION movlw B’00000011’
ACTIVITY 5C movwf PORTB
Find out what stop: goto stop
task this very
short sample PIC Assembly language programs are often written for tasks that need to be
assembly program
speedily executed, for example, parts of an operating system, central heating
is performing.
system or controlling a robot.
150
▲ Table 5.3 Similarities and differences between assemblers, compilers and interpreters
151
computer then executed on another type of computer. of computer and run on another type of computer.
A compiler finds all errors in a program. One error detected It is easier to develop and debug a program using an
can mean that the compiler finds other dependent errors interpreter as errors can be corrected on each line and
later on in the program that will not be errors when the the program restarted from that place, enabling the
first error is corrected. Therefore, the number of errors programmer to easily learn from any errors.
found may be more than the actual number of errors.
Untested programs with errors may cause the computer to Untested programs should not be able to cause the
crash. computer to crash.
The developer needs to write special routines in order to Partial results can be viewed during development,
view partial results during development, making it more enabling the developer to make informed decisions about
difficult to assess the quality of particular sections of a section of code, for example whether to continue,
code. modify, or scrap and start again.
End users do not have access to the source code and If an interpreted program is purchased, end users have all the
the run-time libraries, meaning they are unable to source code and the run-time libraries, enabling the program
make modifications and are reliant on the developer for to be modified as required without further purchase.
updates and alterations.
▲ Table 5.4 Pros (blue cells) and cons (white cells) of compilers and interpreters.
Source code:
public class HelloWorld
{
public static void main(String[] args)
{
System.out.println("Hello World");
}
}
152