Java Reference
In-Depth Information
have to enter the instruction as binary code. For example, to add two numbers, you might have
to write an instruction in binary code, like this:
1101101010011010
1.3.2 Assembly Language
Programming in machine language is a tedious process. Moreover, programs written in
machine language are very difficult to read and modify. For this reason, assembly language
was created in the early days of computing as an alternative to machine languages. Assembly
language uses a short descriptive word, known as a mnemonic , to represent each of the
machine-language instructions. For example, the mnemonic add typically means to add num-
bers and sub means to subtract numbers. To add the numbers 2 and 3 and get the result, you
might write an instruction in assembly code like this:
assembly language
add 2, 3, result
Assembly languages were developed to make programming easier. However, because the
computer cannot understand assembly language, another program—called an assembler —is
used to translate assembly-language programs into machine code, as shown in Figure 1.8.
assembler
Assembly Source File
Machine-Code File
...
add 2, 3, result
...
...
1101101010011010
...
Assembler
F IGURE 1.8
An assembler translates assembly-language instructions into machine code.
Writing code in assembly language is easier than in machine language. However, it is still
tedious to write code in assembly language. An instruction in assembly language essentially
corresponds to an instruction in machine code. Writing in assembly requires that you know
how the CPU works. Assembly language is referred to as a low-level language , because
assembly language is close in nature to machine language and is machine dependent.
low-level language
1.3.3 High-Level Language
In the 1950s, a new generation of programming languages known as high-level languages
emerged. They are platform-independent, which means that you can write a program in a high-
level language and run it in different types of machines. High-level languages are English-like
and easy to learn and use. The instructions in a high-level programming language are called
statements. Here, for example, is a high-level language statement that computes the area of a
circle with a radius of 5 :
high-level language
statement
area = 5 * 5 * 3.1415
There are many high-level programming languages, and each was designed for a specific
purpose. Table 1.1 lists some popular ones.
A program written in a high-level language is called a source program or source code.
Because a computer cannot understand a source program, a source program must be trans-
lated into machine code for execution. The translation can be done using another program-
ming tool called an interpreter or a compiler.
source program
source code
interpreter
compiler
An interpreter reads one statement from the source code, translates it to the machine
code or virtual machine code, and then executes it right away, as shown in Figure 1.9a.
 
Search WWH ::




Custom Search