How instruction execution works in Von Neumann architecture
In our last post about Von Neumann's architecture (http://skjorrface.blogspot.it/2013/06/step-by-step-instruction-execution-in.html), first one of this series is here (http://skjorrface.blogspot.it/2013/05/von-neumanns-architecture-how-modern.html), we've described what parts are actually involved in the architecture, what registers, which parts of the CPU etc. In this post we're going to show a practical exercise of instruction execution. We want to calculate the value of the following expression: (a + b) * (c + d), reading a, b, c and d variables from an input device and writing them onto an output device. A general, simple algorythm would pass through the following steps:
Read values a, b, c and d from the input device;
save the partial result into memory;
multiply the partial result just calculated (c + d) by the previous memorized partial result (a + b);
Write final result onto the output device and show it;
Stop the program execution.
This program requires the use of memory cells, that are normally reserved for programs. Let's suppose these cells are 16, 17, 18 and 19 and that they're respectively reserved for values a, b, c and d and that also cell 20 is available. Von Neumann machine will be able to solve this problem using this specific algorythm (an extension of the above algorythm):
Put into central memory, into cell number 16 (reserved for a), the value read from the input device (this value is available in the Peripherical Command Register [PDR]): do the same for b, c and d, put them into cells 17, 18 and 19;
copy the content of cell number 16, matching "a" to register A (A is a CPU register used for calculations);
copy the content of cell number 17, matching "b" to register B (B is another CPU register used for calculations);
sum up the values of these two registers (this is made by ALU);
store the temporary result to cell 20;
copy the content of cell number 18, matching "c" to register A;
copy the content of cell number 18, matching "d" to register B;
sum up the contents of these two registers (made again by ALU);
execute multiplication of (a + b) by (c + d);
copy the content of cell 20 to register B, containing the partial result of "a + b";
multiply the content of register A (which still contains the value "b + c" by the content of register B ("a + b);
write the result to the output device and show it;
Stop the program execution.
This is how a modern computer architecture works when making calculations, it might seem industrious but if you think we have CPU which make one of those 15 steps in a bilionth part of a second divided by three of four or five according to how much money you spent to buy a CPU (or how much you overclocked it), then you can understand what a powerful invention John Von Neumann architecture is.