Back

High level code v machine code

Introduction
Computers use digital signals to work but humans don't think and work in 'digital'. We use words and sentences to express meaning. The question here is, 'how can a computer, which is digital, be programmed to do useful things by a human, who is not digital'?

Bits and bytes
Computers use digital signals. What this actually means is that the electronic chips inside any computer work by using just two different voltage levels. We humans can represent these voltage levels simply by using a 'one' for a high voltage and a 'zero' for a low voltage. A single BInary digiT (or bit) is either a one or a zero. By grouping together these bits (usually in groups of eight, known as a 'byte') we can create patterns. These patterns can then be used to represent instructions, which tell a computer's processor to do something (like 'add', or 'subtract', or 'store some data' and so on), or data, which can be worked on by the processor. Here is a stream of bytes:

11010011 01110000 11010101 10000111 11111101 01010001 11110001 01111100 11000000

The problem here for humans is that it is very difficult for us to read these patterns of ones and zeros. We don't know easily what each of the above patterns represent. What instruction does the first byte represent, or is it a piece of data, or is it in fact partly an instruction and partly data?

Machine code
Every computer has a processor. That processor has a fixed number of instructions which it can carry out. All of the instructions together, which a particular processor can carry out, is known as the 'machine code' for that processor. Any particular instruction can be represented as a binary pattern.

Assembly programs
Early programmers wrote programs in binary, which the processor of a computer could work with although we know humans don't find working with patterns of ones and zeros very easy at all. For this reason, programming 'languages' were developed.

The first kind of programming languages were known as 'assembly languages'. These are also known as 'low level languages' because the instructions used in assembly languages are very close to the machine code instructions CPUs use. Instead of writing in binary patterns, which corresponded to machine code instructions, programmers wrote in 'mnemonics'. Here is an example of an assembly program:

ADD #344A
DEC IY
CALL Page
LD B, #1195

A 'mnemonic' is a code for a processor's instruction, which is easy to remember. 01110111 isn't easy to remember but ADD is. It is easier to remember a few hundred mnemonics that make up the machine code for a particular processor than it is to remember a few hundred different bit patterns! Whilst this was an improvement, it was still quite hard to learn how to write programs, to read them and modify them.

High level languages
The next type of language that was developed used actual English words rather than mnemonics. They were known as 'High level languages' and aimed to overcome the problems of learning to read, write and modify programs written in machine code or assembly languages by using English Keywords. These types of languages could now be used to express problems in much the same way as humans might logically solve a problem, which was a major improvement on what went on before. A typical program might look like this:

WRITE "Press C to continue".
READ KeyPress
WHILE (KeyPress NOT EQUAL TO C) DO
BEGIN
WRITE "Press C to continue".
READ KeyPress
END
ENDWHILE

Can you work out what the above program actually does? You can see real words like 'WRITE' and 'READ' in the program. These are known as 'keywords' or 'reserved words'. Any particular programming language has a set of these special keywords and the programmer can use them to write programs and make the processor behave in a certain way.

There are many different high level languages in existence. You may have heard of some of them: BASIC, Java, JavaScript, Visual Basic, C and so on. They each have their advantages and disadvantages, their fans and people who don't like them and jobs which they are particularly good at being applied to. Can you find the names of some other high level languages and try to find out what sort of jobs they are good at solving?

 Back