Computer Instructions

KS3 Computer Science

11-14 Years Old

48 modules covering EVERY Computer Science topic needed for KS3 level.

GCSE Computer Science

14-16 Years Old

45 modules covering EVERY Computer Science topic needed for GCSE level.

A-Level Computer Science

16-18 Years Old

66 modules covering EVERY Computer Science topic needed for A-Level.

GCSE Programming Resources (14-16 years)

  • An editable PowerPoint lesson presentation
  • Editable revision handouts
  • A glossary which covers the key terminologies of the module
  • Topic mindmaps for visualising the key concepts
  • Printable flashcards to help students engage active recall and confidence-based repetition
  • A quiz with accompanying answer key to test knowledge and understanding of the module

A-Level Problem solving and programming (16-18 years)

  • An editable PowerPoint lesson presentation
  • Editable revision handouts
  • A glossary which covers the key terminologies of the module
  • Topic mindmaps for visualising the key concepts
  • Printable flashcards to help students engage active recall and confidence-based repetition
  • A quiz with accompanying answer key to test knowledge and understanding of the module

In regards to computer instructions, candidates should be able to:

  • explain how instructions are coded as bit patterns
  • explain how the computer distinguishes between instructions and data.

Computer Instructions: How are program instructions coded?

Machine code instructions are binary numbers and are coded as bit patterns, for example, a 16 bit machine code instruction could be coded as 001010101101001011.
In machine code the instructions are usually made up of 2 parts, an operator (op code) and an operand (typically a memory address). The CPU decodes the operator (for example, the bit pattern 001 could be the code for ADD) to decide what action to take with the operand.
The number of memory bits needed for each instruction (operator plus operand) is important. If only 8 bits were used then 3 bits could be used for the operation codes leaving 5 for the location in memory where the data is stored. This would however be very limiting as there could only be 8 possible operation codes and only memory addresses from 00000 to 11111 could be accessed.
A particular CPU will be designed to process a particular set of machine code instructions and will know:

  • How many bits are used for each instruction.
  • How many of the instruction bits are used for the operator (OP code) and how many for the operand.

The table below represents 9 memory address. Memory address 00000 holds an operator and operand (using 8 bits) and address 00100 holds some data. The CPU would follow the instruction and ADD the value in memory location 00100 to the accumulator.

Memory address Memory contents Explanation
00000 00100100 This memory address has an instruction stored in it, made up of:
the operator (in this case the code for ADD the contents of  a memory address to the contents of the accumulator)
– the operand (in this case, the memory address of the data to be added to the accumulator).
00001 00000000  
00011 00000000  
00100 00010101 This memory address has data stored in it (in this case the number 21 stored in binary)
00101 00000000  
00110 00000000  
00111 00000000  
01000 00000000  
01001 00000000  

 

How does the computer distinguish between instructions and data?

In the Von Neumann architecture used by most computers memory locations are used to store both program instructions and data. The CPU cannot therefore distinguish between instructions and data just by reading the bit pattern stored at a memory address.
The CPU program counter should therefore always contain the memory location of an instruction. If the CPU is instead pointed to a memory address that contains data (either by mistake or because an instruction has somehow been overwritten by data) then the program would fail to run correctly because the CPU would try and interpret the data as an instruction.

Computer instructions such as machine code are instructions are binary numbers and are coded as bit patterns.

Further Readings: