What components will we be using? We have mentioned Registers as being where data being worked on is stored. One of these is the Program or P register. This is essentially a set of flip-flops, one for each ‘bit’ of the instruction. Various bits of this register are then decoded to see what the instruction has to do, for example an add or a test for 0.

Other registers would be used to store data to be added, and for the result, they could also be for data to be sent to a disk or tape drive.

We will look at a simple program to calculate the area of a rectangle. We can use any dimensions using this program, we will use 3×4 for illustration purposes. For this example we only have 5 instructions we can use, an ADD, a SUBTRACT, a STORE, a BRANCH and a STOP. The stop isn’t strictly a normal instruction, but serves the purpose here.

The program is in memory from location zero onwards and looks like this:-

(0)000 – 000 011 000 STORE

(1)001 – 000 100 001 STORE

(2)010 – 001 000 010 ADD

(3)011 – 010 001 001 SUBTRACT

(4)100 – 011 001 010 BRANCH

(5)101 – 100 000 000 STOP

The format for these instructions, or the way the bits are laid out, determines what the instruction does, and what data it uses. We are using a format devised for this illustration. For example here is an ADD instruction

001 001 010

The first three bits are the ‘command’, or what the instruction does. 001 is decoded as an ADD. The rest of the instruction tells us what to add. The next three bits are the address of the register to be added. The last three bits are the register to be added to. This instruction will take the contents of register 000 and add them to the contents of register 010. The result will be placed in register 010.

How do we get data into those registers 000 and 001? We have a STORE instruction. This time the format is:-

000 011 000

Once again the first 3 bits are the command – STORE. The next 3 bits are the data, decimal 3 in this case, the last three are where to store it – in register 0. We will put decimal 3 in register 0.

The SUBTRACT instruction is telling us to subtract a value, in this case 1, from the contents of register 1. The result goes in register 1. (An extra bit not shown here would tell the logic to decode the literal, or actual, value of 1 rather than the address of a register).

The BRANCH instruction is what makes programs capable of powerful things, it is a decision maker. The format is

011 001 010

The first 3 bits are interpreted as a BRANCH instruction and enable logic to decode the rest of the instruction. the next 3 bits are the address of a register to test, and the last 3 bits an address in memory to be used to get the next instruction if the test is not met. Various tests are possible, in this case we are testing for ‘not 0’.

The STOP is used here for this illustration only, normally the program would continue.

Tony is a retired computer engineer, with 40 years experience, building on his previous electronics engineering on radar and automatic controls. He is now working from home on the internet. This article, brought up to date, with diagrams and illustrations, forms part of his latest book. For further information and details, please visit the website Computer Fundamentals.

Leave a Comment