Previous page

11.5.3  Program execution

We now address the final piece of the puzzle concerning machine language programs by illustrating how the machine actually goes about executing a program. At the machine level, all a computer ever does is perform the following task, known as the instruction cycle, over and over.  

The instruction cycle consists of five steps:

  1. Fetch the next instruction from memory.  To do so, load into the instruction register the bit pattern found at the address held in the program counter.

  2. Increment the program counter by one so that it points to the next instruction in the current sequence. 

  3. Decode the current instruction.  This involves correctly identifying the various parts of an instruction based on its op-code.

  4. Execute the instruction.  Operand values are routed to the appropriate arithmetic and logic hardware.  Results are computed and routed to their appropriate destinations.  Appropriate destinations include the general-purpose registers, special purpose registers such as the program counter (in the case of BRANCH and JUMPinstructions) and main memory.

  5. Return to Step 1.

That’s all a computer ever does.

To execute the program of Figure 11.28 a three (0000 0011two) must first be loaded into the Watson Virtual Machine program counter.  The reason for this is that the first executable instruction of the program is located at memory address three.

As the program runs, the machine will faithfully execute the instruction cycle.  First, the instruction “0001 1101 0000 0001” will be loaded into the instruction register.  The program counter will then be incremented from three to four.  Next, the instruction is decoded to mean “load into register D the value stored at memory location one”.  The value at location one will then be loaded into register D.  Since location one was initialized to a two as part of the construction of the program’s data segment, that value will be copied into register D.  Having completed the execution of the current instruction, the machine will return to step one of the instruction cycle.

At this point, the Watson Virtual Machine copies into the instruction register the statement held at memory location four.  The program counter is then incremented to five, so that it points to the next instruction in the current sequence.  The contents of the instruction register “0001 1110 0000 0010” are then decoded to mean “load into register E the value stored at memory location two”.  This instruction is then executed – placing the value three into register E.  Next, the machine returns to the first step in the instruction cycle.

The instruction cycle repeats itself on statement after statement, until a HALT instruction is executed (or the instruction cycle is interrupted by outside influences – such as someone hitting the reset button or tripping over the power cord).

And so, that’s it.  We have arrived at the bare machine that lies underneath the many layers of software.  There is no magic.  No smoke and mirrors.  Just a simple – but very fast – machine running through the instruction cycle over and over, tens or hundreds of millions of times each second.

Exercises for Section 11.5

  1. Translate the program of Figure 11.4 from the assembly language level to the machine language level.

  2. Trace through the program of Figure 11.4 outlining the actions taken during each pass through the instruction cycle.  Be sure to clearly indicate any changes made to the values held in registers or main memory locations.

  3. Translate the program of Figure 11.5 from the assembly language level to the machine language level.

  4. Given the following machine language program, reassemble it into a Watson assembly language program.  Note that the program is assumed to be stored at the top of memory, beginning in location zero, and the first executable statement occurs on the second line of code.


  5. Describe what the program of problem 4 does.  Do so using a single English sentence that even your grandmother could understand.

Return to top