Software Types and Language Translators: Question 2

Syllabus 4.1

Structured 7 marks

A school garden project uses a small computer to log data from sensors and to process the readings. A computing teacher is investigating two events that happen while the logging program is running.

Event 1: A tipping-bucket rain gauge in the garden has a tiny mechanical bucket that physically tips over every time it collects a fixed amount of rainwater. A sensor built into the bucket detects each tip and immediately signals the controlling computer.

Event 2: The logging program, while working out the average rainfall per hour recorded so far today, attempts to divide the total rainfall by the number of hours elapsed, which has become zero because the program was restarted just after midnight, before the first hour had finished.

(a) State whether Event 1 is a hardware interrupt or a software interrupt, and give one reason for your answer. [2]

(b) State whether Event 2 is a hardware interrupt or a software interrupt, and give one reason for your answer. [2]

(c) Describe what happens inside the computer, in general, from the moment either interrupt occurs to the moment the original logging program continues (or is stopped). [3]

Show worked solution Hide worked solution

Worked solution

Part (a): Classifying Event 1

An interrupt is a signal that pauses the currently running program so that its cause can be dealt with. Event 1 comes from the tipping-bucket sensor, a physical device, detecting a real mechanical event (the bucket tipping over) and reporting it to the computer. Because the signal originates from hardware rather than from a mistake in the program’s own instructions, Event 1 is a hardware interrupt.

Part (b): Classifying Event 2

Event 2 happens because the logging program itself tries to carry out an operation that cannot be completed, dividing by an hours-elapsed count of zero. No physical device is involved; the problem is entirely inside the program’s own calculation, caused by the program restarting before a full hour had passed. This makes Event 2 a software interrupt.

Part (c): What happens when an interrupt occurs

Whichever kind of interrupt is raised, the general sequence is the same:

  1. The CPU completes (or safely pauses) whatever instruction it is currently carrying out, and saves the state of the interrupted program so that it can be returned to later.
  2. Control is passed to an interrupt service routine suited to the specific interrupt. One routine might add the tip to the running rainfall total, while another might handle the invalid division so the averaging calculation can recover or stop safely.
  3. Once the interrupt service routine has finished dealing with the cause, the original logging program is resumed from exactly where it was paused, so logging can continue normally. Unless the interrupt revealed a problem serious enough that the program must be stopped instead.

Final answers

  • (a) Event 1 is a hardware interrupt, generated by the tipping-bucket sensor detecting a physical event.
  • (b) Event 2 is a software interrupt, generated by the program’s own divide-by-zero error.
  • (c) The CPU saves the running program’s state, hands control to an interrupt service routine that deals with the cause, and then the original program resumes (or is stopped, if the cause was fatal).