Edexcel International Advanced Level Computer Science, point 1.1.1
Definition
The stored-program concept is the idea that a program's instructions and data are stored in main memory, both in binary. The processor fetches each instruction from memory and carries it out, one after another.
Before this idea, early machines were wired or set up by hand for one task. To change what they did, engineers had to rearrange cables and switches, which could take days.
Function
It lets one general-purpose machine do many different jobs. To run a different program, you load different instructions into memory. The hardware stays the same.
Characteristics
- Instructions and data share the same memory, and both are held as binary patterns.
- Each memory location has an address.
- The processor keeps track of the next instruction using the program counter (PC).
- Instructions are normally carried out in sequence, unless an instruction (a jump or branch) changes the PC.
- Because instructions are just data, a program can be loaded, changed, copied or even created by another program (a compiler produces a program, for example).
Operation
- A program is loaded from secondary storage into main memory (RAM).
- The PC is set to the address of the first instruction.
- The processor fetches the instruction at that address, decodes it and executes it (the fetch-decode-execute cycle, 1.1.5).
- Any results are stored back in memory.
- The PC moves on to the next instruction, and the cycle repeats until the program finishes.
Main memory might look like this, with the program and its data side by side:
| Address | Contents (binary) | What it is |
|---|---|---|
| 0000 | instruction 1 | The PC points here first |
| 0001 | instruction 2 | |
| 0010 | instruction 3 | |
| … | … | |
| 0100 | data item | |
| 0101 | data item |
Nothing in the memory itself says which patterns are instructions and which are data. The processor treats a pattern as an instruction because the PC pointed to it.
Benefits
- Flexible: change the program by changing memory contents, with no hardware changes.
- One machine, many uses: the same computer can run a game, a word processor or a spreadsheet.
- Programs can be stored, copied and shared like any other data.
- Programs that make programs are possible (compilers, installers, operating systems).
- Memory can be shared out as needed between instructions and data.
- The computer can modify its own program or data, because instructions are stored in memory just like data.
- Simpler hardware: one memory and one mechanism handle both instructions and data.
- Fast to start and switch programs: the instructions are already in fast main memory, so they don't have to be read from secondary storage each time.
Drawbacks
- Shared memory and buses create a bottleneck. The processor can't fetch an instruction and read data at the same moment over one path (the von Neumann bottleneck, 1.1.2).
- A faulty or malicious program can overwrite instructions or data, because they sit side by side. This causes crashes and is how some security attacks (such as buffer overflows) work.
- Instructions can be mistaken for data, or the reverse, if a program jumps to the wrong address.
- Needs protection mechanisms from the operating system to stop programs interfering with each other.
Worked example
Task: a washing machine used to be built with a fixed circuit for each programme. Explain how using the stored-program concept would change it.
- A fixed circuit can only ever do the job it was built for. A new wash cycle needs new hardware.
- With the stored-program concept, the wash programmes are held as instructions in memory (often in ROM or flash).
- The processor fetches and carries out the instructions for the chosen programme.
- A new programme or a bug fix is made by changing the stored instructions, with no change to the wiring, and the same hardware can be used in many models.
- Drawback: if the stored instructions were corrupted, the machine could misbehave, so they are usually held in protected memory.
Exam tip: state that instructions and data are both held in main memory in binary. A good answer to a "benefit" question says the same hardware can run different programs by changing what is in memory. For a drawback, name the bottleneck or the risk of programs overwriting each other.
Check yourself
What is the stored-program concept?
Instructions are held in main memory, in binary, alongside the data, and are fetched and executed by the processor one after another.
What does the program counter do?
It holds the address of the next instruction to be fetched.
Give two benefits of the stored-program concept
Any two of: the machine can run any program without being rewired; programs can be stored and copied like data; programs can create other programs; memory can be shared flexibly between instructions and data.
Give two drawbacks of the stored-program concept
Any two of: instructions and data share one path, which creates a bottleneck; a fault or attack can overwrite instructions; instructions and data can be confused; protection is needed.