Monday, January 26, 2009

Example

A traffic light showing red.

Suppose a computer is being employed to drive a traffic light. A simple stored program might say:

  1. Turn off all of the lights
  2. Turn on the red light
  3. Wait for sixty seconds
  4. Turn off the red light
  5. Turn on the green light
  6. Wait for sixty seconds
  7. Turn off the green light
  8. Turn on the yellow light
  9. Wait for two seconds
  10. Turn off the yellow light
  11. Jump to instruction number (2)

With this set of instructions, the computer would cycle the light continually through red, green, yellow and back to red again until told to stop running the program.

However, suppose there is a simple on/off switch connected to the computer that is intended to be used to make the light flash red while some maintenance operation is being performed. The program might then instruct the computer to:

  1. Turn off all of the lights
  2. Turn on the red light
  3. Wait for sixty seconds
  4. Turn off the red light
  5. Turn on the green light
  6. Wait for sixty seconds
  7. Turn off the green light
  8. Turn on the yellow light
  9. Wait for two seconds
  10. Turn off the yellow light
  11. If the maintenance switch is NOT turned on then jump to instruction number 2
  12. Turn on the red light
  13. Wait for one second
  14. Turn off the red light
  15. Wait for one second
  16. Jump to instruction number 11

In this manner, the computer is either running the instructions from number (2) to (11) over and over or its running the instructions from (11) down to (16) over and over, depending on the position of the switch.[15]