Home | Projects | Notes > Computer Architecture & Organization > The Stored Program Concept
Program execution cycle expressed in pseudocode
xxxxxxxxxx
111/* Stored program machine */
2
3 Point to the first instruction in memory
4
5 REPEAT
6 Read the instruction at the memory location pointed at
7 Point to the next instruction
8 Decode the instruction read from memory
9 Execute the instruction
10 FOREVER
11End
Execute the instruction
step in detail (in pseudocode)
xxxxxxxxxx
101/* Execute the instruction */
2
3 IF the instruction requires data
4 THEN fetch the data from memory
5 END_IF
6 Perform the operation defined by the instruction
7 IF the instruction requires data to be stored in memory
8 THEN store the data in memory
9 END_IF
10End
Program execution cycle expressed in C
xxxxxxxxxx
111ProgramCounter = 0; // point to the 1st instruction
2
3do
4{
5 instruction = memory[ProgramCounter]; // read the instruction
6 updatepc(ProgramCounter); // pc point to next instruction
7 decode(instruction); // decode the instruction
8 fetch(operands); // fetch required data
9 execute; // execute the instruction
10 store(results); // store the result
11} while (instruction != terminate);
Stored program machines require two memory access per instruction.
One to read the instruction from memory.
The other to either read data from memory that is required by the current instruction or to put data in memory that previously has been created or modified in the CPU by an earlier instruction.
The term von Neumann bottleneck indicates that one of the problems of the stored program computer is the path between the CPU and the memory.
Harvard Architecture solves this issue by using separate storages and buses for data and instructions.
Store program machines are said to operate in a two-phase mode called a fetch/execute cycle.
Format
xxxxxxxxxx
21Operation Address1, Address2, Address3
2(Operation Destination, Source1, Source2)
Operation
specifies the action the instruction is to carry out (e.g., add, subtrace, multiply, etc.) andAddress1
,Address2
,Address3
are the locations of the three operands in memory.There is a standard for the way in which the sequence of operands is written. Different computers may use the different notation.
Equivalent RTL Notation
xxxxxxxxxx
21[Address1] ← [Address2] Operation [Address3]
2([Destination] ← [Source1] Operation [Source2])
Example
xxxxxxxxxx
21ADD P, Q, R
2[P] ← [Q] + [R] // in RTL notation
ADD P, Q, R
is the symbolic form of the actual instruction that would be stored in memory as a binary sequence of 1s and 0s, meaning "add the contents ofQ
to the contents ofR
and put the result inP
".
P
,Q
, andR
are the symbolic names of the addresses of three memory locations.This operation requires four memory accesses (e.g., one to fetch the instruction, two to fetch the two source operands, and one to store the result).
Here
ADD
is called an op-code (abbreviated from operation code ). An op-code is the portion of a machine language instruction that specifies the operation to be performed.
Format
xxxxxxxxxx
21Operation Address1, Address2
2(Operation Destination, Source1)
Address2
is a source operand andAddress1
is both a source and a destination operand.The source operand
Address1
is replaced (overwritten) by the result.Practical computers do not generally allow you to use two memory addresses in the same instruction. Most computers specify one address in memory and a second address as a register.
Equivalent RTL Notation
xxxxxxxxxx
21[Address1] ← [Address1] Operation [Address2]
2([Destination] ← [Destination] Operation [Source])
Example
xxxxxxxxxx
21ADD P, Q
2[P] ← [P] + [Q] // in RTL notation
Format
xxxxxxxxxx
11Operation address
Example
xxxxxxxxxx
31LOAD Q (Read Q into the accumulator)
2ADD R (Add R to the accumulator)
3STORE P (Store the accumulator in P)
Above instructions simply mean
P = Q + R
.Because only one address is provided and at least two addresses are required, the processor has to use an operand that doesn't require an explicit address (
Q
in this example). That is, this operand comes from a register once called the accumulator within the CPU.In some cases, accumulator acts as a bottleneck, because all of the data has to flow through it.
Addressing modes are an aspect of the instruction set architecture in most CPU designs.
The various addressing modes that are defined in a given instruction set architecture define how the machine language instructions in that architecture identify the operand(s) of each instruction.
An addressing mode specifies how to calculate the effective memory address of an operand by using information held in registers and/or constants contained within a machine instruction or elsewhere.
Examples
Location of an operand given directly (i.e., it's in location 1000
).
Location of an operand given indirectly (i.e., register 6
contains the address of the operand we need).
Computers can be classified by the way in which their instructions act on data.
Memory-to-memory
Instructions can read source operands from memory, perform an operation on the data, and store (return) the result in memory.
These types of computers (CPUs) do not even require the use of registers to execute instructions.
Register-to-register
Computers that perform operations only on the contents of registers.
Also called, load/store computers since LOAD
and STORE
operations are the only memory access instructions provided.
LOAD
instruction must be used to put the data in registers.
STORE
instruction must be used to transfer data from a register to memory.
Falls into the class of RISC
e.g., ARM, MIPS
Register-to-memory
Computers that can perform operations on two operands where one is in memory and the other in a register (the result is written to either memory or a register).
Falls into the class of CISC
e.g., Intel IA32 (8086, Pentium, Core i7)