Programming Languages

advertisement
CH/S5CIT/Oct. 2006.
Programming Languages

Programming. The systematic procedures for producing solutions that solve information problems

Programming Languages. They are languages used to realise an algorithm of a computer solution.
Machine Code

It is a language which is the only language that a computer CPU can read, i.e. the machine instruction set.

All other programming language programs must be translated into machine language before they can be
executed.

Suitable instructions must be input and stored into the main memory before the actual processing to be executed.

The instructions are written in machine-readable (i.e. thus binary form) codes.

Operation code. This part specifies the function or operation to be performed (e.g. add, load, jump, ..., etc.).

Operand address. This part specifies the data (operand) or the locations of data to be processed.

Each computer CPU has its own machine-readable instruction set, which has a particular format.
Here are two sample machine code programs:
program instruction
memory
location
opcode
operand
address
remark
00000 (0)
110
00000
00001 (1)
00010 (2)
101
110
01111
00000
00011 (3)
000
01111
00100 (4)
111
00000
input the first number (say “2”) into accumulator; the computer will
wait until data signals are received.
Store “2” from accumulator into location 15 in central memory.
Input the second number (say “5”) into accumulator; the computer will
wait until input data signals are received.
add “2” from location 15 in main memory to “5” in accumulator, the
result “7” is now in accumulator.
output the result “7” to the output device.
memory
location
machine code
content of
Accumulator
remark
10000
10001
10010
10011
10100
10101
10110
10111
11000
11001
11010
11011
11100
11000000
10101111
11000000
10101110
11000000
10101101
11000000
10101100
00001101
00001110
01101111
10101011
11100000
3
3
6
6
8
8
10
10
18
24
8
8
8
input ‘3’
store ‘3’ into location 15
input ‘6’
store ‘6’ into location 14
input ‘8’
store ‘8’ into location 13
input ‘10’
store ‘10’ into location 12
add ‘8’ to accumulator
add ‘6’ to accumulator
divide ‘24’ by ‘3’
store ‘8’ into location 11
output ‘8’ to output device
PROGRAMMING LANGUAGES
page 1
CH/S5CIT/Oct. 2006.
Assembly Language

It is tedious for a programmer to write a machine code program because the programmer is required to memorise
the operation code for each instruction and the actual address location for each variable addresses.

More meaningful letter symbols or semi-word  mnemonics  is used for the binary machine opcodes and
variable addresses.

The language written in these mnemonics is called the
assembly language
.
Usually, each
mnemonic in the assembly language has one to one corresponding in the machine language instruction set, i.e. if
you find one assembly language instruction, it will match with one and only one machine language instruction,
and vice versa.

Assembly language is machine-oriented, and thus machine dependent.

An assembler
codes.
is a program that translates an assembly language program into the equivalent machine
Sample 1:
Opcode
Mnemonics
Meaning
Address
(dec. bin.)
Mnemonic
Machine
code (bin.)
Meaning
000
BRK
Stop
12 01100
LDA 18
001 10010
Load contents of cell 18 to Ac
001
LDA
Load Accumulator
13 01101
CMP 19
101 10011
Compare Ac with contents of
cell 19
011
STA
Store Accumulator
14 01110
BPL 16
110 10000
If larger go to instruction 16
101
CMP
Compare Accumulator
15 01111
LDA 19
001 10011
Otherwise load contents of 19
to Ac
110
BPL
Branch if Positive
16 10000
STA 20
011 10100
Store contents of Ac at cell 20
17 10001
BRK
000 00000
Execution stops
High Level Languages

Assembly languages and machine languages both relate closely to the architecture of the processor and hence are
machine dependent. We call such languages as low level languages.

There are problems in using low level languages:

i.
Details knowledge about the registers and architecture of a particular machine is necessary.
ii.
More attention should be drawn from the operational aspects of the CPU.
iii.
They are machine dependent.
Advantages of high level language.
i.
easier to learn and faster to write
ii.
easier to add documentation
iii.
throughput of programmers increased
iv.
rules and syntax for different needs
v.
few concerns of details of the structure of computers
vi.
Portability: Programs written in high level languages for one computer can be run on another. That is, these
programs are portable
.
vii.
Because of the portability of programs, a program library can be set up. Standard programs performing
specific jobs are available.
PROGRAMMING LANGUAGES
page 2
CH/S5CIT/Oct. 2006.



Disadvantages of high level languages
i.
complicated rules and syntax
ii.
too specialised for one purpose
iii.
larger object programs
5 common types of high level languages
i.
Commercial languages, e.g. COBOL, RPG
ii.
Scientific languages, e.g. ALGOL, FORTRAN, BASIC
iii.
Special purpose languages, e.g. ADA, CSL
iv.
Command languages for operation system, e.g. JCL
v.
Multipurpose languages, e.g. PL/1, LOGO, C, Pascal
Comparison between the low and high level languages
low-level language
high-level language
1. Machine dependence
Yes
Not usually
2. Detailed knowledge of machine in use required
Yes
Not usually
3. Access to basic machine features
Yes
Not usually
4. Program preparation costs (coding, debugging and
documentation
Higher
Lower
5. Translator
Assembler
Compiler or interpreter
6. Object program
Shorter and faster
Longer and slower
7. Equivalent machine code instruction
One-to-one
One-to-many
Translators

A translator is a special system program which translates the program written by human into machine language.

The program to be translated is often called source
object program .

Three types of translators
i.
ii.
iii.
program while the resulting program is called
Assembler
a.
Translate assembly language to machine codes.
b.
It must finish translating the whole program before the program can be executed.
Compiler
a.
Translate high level language to machine codes
b.
It also must finish translating the whole program before the program can be executed.
Interpreter
a.
Translate high level language to machine codes.
b.
It usually translates one high level instruction and then executes it immediately, and so on. The
interpreting process follows the logical sequence of the source program (e.g. BASIC interpreter).
PROGRAMMING LANGUAGES
page 3
CH/S5CIT/Oct. 2006.

Comparison between the translators
i.
The works of compilers or interpreters are more complicated than those of assemblers.
ii.
Once the object program is produced by the compiler and assembler, the execution of the program is very
fast as compared with executing one using an interpreter.
iii.
The interpreter handles one source statement at a time  useful in debugging.
iv.
Interpreter is useful in simulating one computer to another (i.e. it makes one computer work like another).
v.
If the source program has to use again and again, using an assembler or a compiler to produce an object
program make more sense.
vi.
Sometimes, a compiler only translates the source program into a low level language program (e.g. assembly
languages).
Source programs
High level
language programs
Assembly programs
Translators
Object programs
Compiler
Interpreter
Machine codes
Assembler
Fig. 2 Three types of translators
EXECUTION
Generations of Program Languages

1st generation: Machine languages

2nd generation: Assembly language

3rd generation: Procedural languages, e.g. Pascal, C++

4th generation: Problem oriented languages, e.g. SQL.(Structured Query Language)

i.
Non-procedural
ii.
Telling what we want rather than how we find the solution
5th generation: Natural languages, e.g. English, Japanese.
Trends of Program Languages

Computer scientists found that programs should be written in a structured, modular way which can be
understood and debugged easily.

Constructs like IF...THEN...ELSE, FOR...NEXT, WHILE...WEND, DO...LOOP, SELECT...CASE, etc. are
considered basic to a structured language.

Structured programming led to 2 trends:
i.
Object-oriented. Program have fully debugged should be reusable. Emphasis is on regarding procedures
and data structure as a whole (object). The approach led to object-oriented programming (OOP).
ii.
Event-oriented.(event-driven) Another trend is event-oriented, especially in the Windows environment
where a single, double or triple to click initiates a procedure.
PROGRAMMING LANGUAGES
page 4
Download