We start with the instruction in location 000. The processor requests this instruction by setting the address register to 000 and sending a request to memory. The first instruction is loaded into the P register. The first 3 bits tell the logic this is a STORE instruction, and enable gates to take the value in the next 3 bits, and place it in the register decoded from the last 3 bits. We place 3 in register 0. Instruction complete, get next instruction (add 1 to address register).
The next instruction, from 001, is also a STORE, and we load a value of 4 into register 1.
The third instruction, from 010, is an ADD. We add the contents of register 000 (3) to register 010 (initially 0) giving 3 in register 010.
Next, from 011, we have a SUBTRACT, which is used to count down. This would normally not require a separate instruction, but we use it here to demonstrate the principle. We subtract a value of 1 from register 001 going from 4 to 3.
The next instruction, from 100, the BRANCH, checks the count, in register 001 (second 3 bits) looking for not equal to zero. The data in register 3 is not zero, so we enable the last 3 bits, 010 to the ADDRESS register. Now the next instruction will come from location 010, not the next sequential address. This is the Branch out of sequence.
With an address of 010, the next instruction is the ADD again, which adds another 3 to register 010 totaling 6. We again subtract 1 from the count, check for not zero, and return once more to address 010. when we have added 3 on the fourth time through the loop, the count goes to zero, the BRANCH test fails, so, instead of branching, we take the next instruction in sequence, and STOP.
With any luck the RESULT in register 010 will be 12, which is the area of a 3x4 rectangle. We can calculate any area by substituting the dimensions in the STORE instructions.
The area around the instruction decode area is where the ingenuity of the logic designer shows. With a fixed number of bits in the instruction to play with, though of course more than the 9 bits we have used here, he must make the most of what there is. Working against this is the cost of incorporating complicated logic in the overall layout of the system, and the possible problems which may arise with unforeseen applications, or sequences of instructions.
Also to be considered is the instruction stack, or pipeline. As we saw in the article on cache memory, a speed increase can be obtained by fetching 4 instructions at once. We can go one step further and load these instructions into the processor. It is then possible to start working on the next instructions before the current one is finished. However if the current instruction performs a branch, this work must be discarded.
History Of First Computer
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 3x4 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.
In Part 3 we will see how this program can give us the area of a rectangle
Bio Diesel In India You contribute to pollution by driving you reduce the pollution by planting trees! You are carbon neutral! Save energy by using renewable products available via companies listed in the green direc...