Programming |
For computer hardware to perform a useful task it must be given a set of instructions to tell it what to do. A program is a sequence of instructions which tells the hardware how to carry out a particular job.
New programs are usually only created if there is no existing software package that will perform the same job. Writing a program involves a lot of work so if you can carry out a task with an off-the-shelf package such as a database you will probably find it much easier and cheaper to use the existing package. Developing a sophisticated computer program may take many thousands or even tens of thousands of man hours.
Because developing a program is a complicated task it is important that the program is planned properly before it is written. Programmers usually follow the systems life cycle when developing a program. Tools such as flowcharts are used to plan how a program will operate. The programs that you use such as computer games, utilities and desktop publishers were all created with a programming language.
There are different levels of programming language. Most computer programs are written in a high level language but for some tasks a low level language must be used.
A computer can only process (execute) instructions that are written in machine code. A machine code instruction is a sequence of 1s and 0s. An example instruction which tests if a bit in memory is set to 1 is 0010100101110100110110. The machine code program below will convert an upper case letter stored in a particular memory location to lower case :
Machine Code Program | Explanation |
000011010100101010000000 | Load the contents of memory location E00 into the accumulator. |
01101001 | Clear the carry flag. |
0010101001000000 | Add 32 to the content of the accumulator. |
000001010100101010000000 | Store the result back in memory location E00. |
As you can see the program is quite difficult to understand! An assembly language is a set of simpler instructions (or mnemonics) which correspond to the machine code instructions that a computer understands. The assembly language equivalent of the program above is :
Assembly Program | Explanation |
LDA &E00 | Load the contents of memory location E00 into the accumulator. |
CLC | Clear the carry flag. |
ADC #32 | Add 32 to the content of the accumulator. |
STA &E00 | Store the result back in memory location E00. |
The program is still quite difficult to understand, but the instructions used in the program are much easier to remember than the binary codes in the machine code program.
A program called an assembler must be used to translate a program which has been written in an assembly language into machine code so it can be executed. Software such as operating systems and embedded control systems which must run in computers with only a small amount of memory are usually written in assembly language. For example a program to operate a washing machine would probably be written in assembly language.
Advantages and disadvantages of using assembly languages to produce programs are :
Advantages | Disadvantages |
It is much easier to learn assembly language instructions than
machine code instructions. But it is still fairly hard to
remember the instructions. Programs written in assembly language can run faster and use up less memory than programs to do the same job written in a high level language. | Programs written in assembly language on one computer
will not work on a different type of computer. A programmer needs to know an awful lot about the computer hardware he is using to write a program in an assembly language. |
High level languages were developed to simplify programming further. Most high level languages were first created in the 1960s and 1970s when computer hardware became much more powerful and hence speed of execution was less important. High level languages use instructions which are much more like written English. Each high level instruction can do the job of many low level instructions.
Many different high level languages are available. Here are some examples :
C++ | A general purpose language which can be used for most tasks. C++ programs usually execute faster than programs written in other high level languages. |
COBOL | Used for business applications such as customer databases. |
BASIC | A general purpose programming language originally designed for use on home computers. |
Logo | Developed for use in education, used to draw pictures and control devices such as a robot turtle. |
Each programming language has its own commands and structures that can be used. The allowed commands and structures are known as the syntax of the language.
Because a computer can only execute instructions that are written in machine code, a high level language program must be translated into machine code before it can be used. This task can be carried out automatically by computer software.
Advantages and disadvantages of writing a program in a high-level language are :
Advantages | Disadvantages |
Instructions are much easier to remember and use than assembly
language instructions. High-level programs are much easier to understand than assembly language ones. Fewer instructions are required to write a program than when using assembly language. A program can usually be developed much more quickly using a high level language than an assembly language. A program written in a high level language on one type of computer can usually be converted to operate on another type of computer quite easily. Because of this high level language programs are described as being portable. | High-level language programs normally take up more space and execute more slowly than equivalent assembly language programs. |
High level language programs must be translated into machine code before they can be executed. This can be done automatically using either an interpreter or a compiler.
Programs are often developed using an interpreter because an interpreter can execute working parts of a program even if some parts do not yet work. When the program works properly it is then compiled so it will run faster and use up less memory. Most sophisticated, large computer programs are written using high-level languages.
Some languages such as BASIC usually use an interpreter. Other languages such as Pascal normally use a compiler.
GCSE ICT Companion 04 - (C) P Meakin 2004