Languages and programs: programming languages and Fortran

Programming languages

In the early days of computing, programmers wrote these instructions as sequences of binary Os and ls. This is called machine code, as it is the code or 'language' that the machine understands. A program to carry out quite a simple task will consist of many machine code instructions, and so program­ writing in the early days was a time-consuming and arduous task. Machine code is sometimes called the 'first generation' programming language.

To simplify matters and speed up the task of program­ming, assembly languages were developed. These were one stage removed from machine code in the direction of human-understandibility, and are sometimes called 'second generation' programming languages. With these, program­ mers could write instructions in an easier form, using commands such as LDA, meaning 'load accumulator',

ADC, meaning 'add with carry', and CLC, meaning 'clear carry'. The assembly language converts these commands into the strings of binary Os and ls that the computer understands.

Although these commands take away the need to know anything about the sequence of bits that must be sent to the control circuit, they do demand a good knowledge of what goes on inside the computer in order to perform even simple tasks such as addition or subtraction. For example, you need to know that numbers to be added or subtracted have to be loaded into the accumulator (a special area of working memory in the CPU), and you have to tell the computer to 'carry' numbers when performing addition. Here is the sequence of assembly language commands for adding 2 and 2 on computers which use the 6502 microprocessor (such as the original Apple computer or the BBC micro). An expla­ nation is given at the right of each command.

image

Because in both machine code and assembly language you are working close to the level of the computer and require an intimate knowledge of the way in which it works, they are called low-level languages. Furthermore, since these languages are addressing the actual circuitry inside the CPU, they are machine-dependent, meaning that they vary from one type of computer to another. So computers based on the 6502 microprocessor use a different assembly language to PCs which are based on the Intel 8086 family of microprocessors.

Nowadays, most programming is done in high-level languages. They are called this because they are a further level away from the level of the machine, and their com­ mands are such that you don't need to know anything about the computer's circuitry in order to write programs. The commands are, in fact, fairly close to the language of ordinary English and arithmetic. For example, to add two variables A and B in many high-level languages, you simply type 'A+ B'.

This not only makes programming easier, it means that programs written in these languages are not restricted to particular types of microprocessor. In theory, such a pro­ gram will run on any computer, though some modifications may be required to cope with hardware differences, e.g. screen display differences. In practice, some languages, notably BASIC, vary somewhat from computer to com­ puter, and BASIC programs written for one may require extensive modifications before they will run on another.

Although programs in high-level languages are relatively easy for humans to write, they are not directly comprehen­sible to the computer, which needs detailed instructions in the form of binary Os and ls. So the computer must translate these commands into its low-level language. The high-level language program written by the programmer is called the source program, the machine-language translation is called the object program.

With some high-level languages, this translation job takes place while the program is being run. This means that the computer has to translate commands and execute them at the same time, which slows the program down. This type of translation is called interpretation and is carried out by a piece of system software called an interpreter. The most well-known interpreted language is BASIC (see page 83). Interpreted languages require relatively small amounts of computer memory to run, one reason why BASIC became so popular on microcomputers, which used to have severely limited amounts of RAM.

With most high-level languages, however, the program is translated before it is run. This type of translation is called compilation, and is carried out by a piece of software called a compiler. A program that has been translated is said to be compiled. It is then run in its compiled form. Compiled programs don't need the presence of the original language in the computer in order to run, and they run much faster than programs that have to be interpreted. Because of these advantages, compiled versions of BASIC have been pro­ duced and are available on many computers.

Well-known compiled languages are COBOL and C, both of which are standardized across a wide range of machines. COBOL is mainly used on large computers, and is the language of data processing, and C is used across a range of computers including microcomputers. A program written in C can be compiled for a variety of different computers, and then sold in its compiled form for those computers.

Many hundreds of programming languages exist, each with their strengths and weaknesses. Three of the most widely used are FORTRAN, BASIC and COBOL, and these are described briefly below. I have also included a brief account of PROLOG, which is a quite different type of language used mainly in expert system applications. These high-level languages are sometimes called 'third gen­ eration' programming languages.

clip_image002

FORTRAN

The development of FORTRAN was started by IBM in 1954, and it was first put to use in that organization in 1957. FORTRAN is short for FORmula TRANslation and, as this name implies, it was designed for engineering, statistics, and other mathematically-oriented applications. It is good at carrying out complex calculations, which can be coded as compressed statements much like ordinary mathematical formulae. It requires a large compiler, which limited its use to computers with reasonably large amounts of memory.

Being almost the first high-level language, FORTRAN became firmly entrenched as the language for scientific use, and it still retains that position. BASIC, the most popular language of all for general-purpose use, was derived from FORTRAN.

A program written in FORTRAN consists of a list of numbered statements, called program lines, which express in a compact form a sequence of instructions to the com­ puter. There are four kinds of statement, which we can think of as analogous to the four kinds of task - control, arithmetic/logic, input and output- that go on in a computer system (see the start of Chapter 2):

• Control statements.

• Arithmetic statements.

• Input statements.

• Output statements.

Control statements tell the computer how to sequence its execution of the program. Normally, the program lines will be executed in numbered order, but if in line 50 there is the control statement GOTO 100, the computer will branch straight to line 100, missing all the intervening program lines. This does not mean that those program lines are unnecessary; the GOTO statement may be an option that is executed only if a certain state of affairs exists, such as a value being more than a certain amount. Testing for certain conditions, and then branching on the results of the tests, is a very important part of most programs.

Arithmetic statements govern the calculations that take place when the program is run. In FORTRAN, these are similar to the statements of ordinary arithmetic, using plus (+), minus (-), multiplication(*), division(/), powers and brackets in the usual way. For example, to calculate the total price T of N items which cost £P each, with VAT at 17.5% added on, the statement might be written like this:

T=N*P*17.5

Input and output statements govern the input of data into the computer and the output of the results. For example, the statement

READ (5) N, P

would tell the computer to read from device 5 (which would be some form of input device) the values given to N and P.

Comments

Popular posts from this blog

WORKED EXAMPLES ON PROCESS SPECIFICATION.

Why do we need information systems, management structure, requirements of information at different levels of management.

The User Interface:Establishing User Interfaces