Chapter 6
|
 |
CS 103 Lesson 1

Assemblers, Interpreters, and Compilers
The
machine language of
a computer is actually hardwired into the microprocessor of that machine. The microprocessor at
the right is shown about actual size. Yet, it contains many miles of circuitry and millions of
transistors and other electrical components (The
Intel Pentium IV contains 42,000,000 transistors
). The transistors act as switches which can be set
by the program to cause electrical current to flow along different paths thereby affecting the
behavior of the machine. These modifications to the circuitry of the microprocessor are the "instructions"
that the machine "understands". Since various families of computers use different microprocessors,
they use different machine languages. The machine language of a PC is different from that
of the Sun workstation which is different from Apple Macintosh. Yet each of these computers is
able to execute a program written in C++ or FORTRAN or Java. This is possible because other
applications can
translate a program written in one of these high-level languages
(source code) into the computer's own low-level machine language (object code). |
 |
There are three general categories of translator programs:
assemblers, interpreters, and compilers.
High-level program ----> Assembler, Interpreter, Compiler -----> Low-level instructions
Source code ----> Assembler, Interpreter, Compiler -----> Object code
Assembler languages use a set of abbreviated words (mnemonics)
to represent the instruction set of the microprocessor. An assembler language program must be developed for
each different microprocessor since their instruction sets are different. For example, every microprocessor
contains a circuit that connects to a special part of the computer's memory called the accumulator.
An assembler language for that microprocessor must then contain a mnemonic that generates the binary code
that activates that particular function of the microprocessor. In the simulation program we will use later,
that mnemonic is the LOD (pronounced LOAD) instruction. The programmer must memorize the mnemonics that are
associated with the particular assembler language for a specific microprocessor. Once a program is written,
the assembler translates the mnemonics into the binary instructions that control the microporcessor.
Interpreters are programming languages that remove the
programmer even farther from the microprocessor. Interpreted languages allow the programmer to use his/her
own language to write programs. A single line of code may generate many machine language instructions.
As you will see later, the single JavaScript statement total = cost + tax; would generate at least
three machine language instructions. Interpreters generate the machine language instructions for a statement
each time they encounter that statement. If a set of statements is contained in a loop, each statement is
reinterpreted each time through the loop.
Compilers are similar to interpreters in most respects.
However, they differ in one important way. Compilers translate the entire program into machine
language and then store those instructions in a separate file. Once a program has been
compiled without error, it never needs to be translated again (unless the programmer changes the program).
The following table compares the three types of translators.
Program Translators
Translator |
Characteristics |
Examples |
Assembler |
- Microprocessor specific
- Programs are not portable
- Programmer must understand the architecture of the microprocessor
- One instruction - One operation correspondence
- Program executed very quickly (native code)
|
Each microprocessor has its own assembler language
|
Interpreter |
- Microprocessor specific
- Programs are portable
- Programmer does not need to know the architecture of the machine
- One statement may generate multiple instructions
- Programs run relatively slowly
|
BASIC
LISP
JavaScript
|
Compiler |
- Microprocessor specific
- Programs are portable
- Programmer does not need to know the architecture of the machine
- One statement may generate multiple instructions
- Program executed very quickly (after compilation)
|
C and C++
FORTRAN
Pascal
COBOL
Java
|
Top
|