Instructions can be classified as one of three major types: arithmetic/logic, data transfer, and control. Arithmetic and logic instructions apply primitive functions of one or two arguments, for example addition, multiplication, or logical AND. In some machines the arguments are fetched from main memory and the result is returned to main memory, but more often the operands are all in registers inside the CPU. Most machines have a set of general purpose registers that can be used for holding such operands. For example the HP-PA processor in Hewlett-Packard workstations has 32 such registers, each of which holds a single number.
The data transfer instructions move data from one location to another, for example between registers, or from main memory to a register, or between two different memory locations. Data transfer instructions are also used to initiate I/O operations.
Control instructions modify the order in which instructions are executed. They are used to construct loops, if-then-else constructs, etc. For example, consider the following DO loop in Fortran:
DO 10 I=1,5 ... 10 CONTINUE
To implement the bottom of the loop (at the CONTINUE
statement) there might be an arithmetic instruction that adds 1
I, followed by a control instruction that compares
5 and branches to the top of the loop if
I is less than or
equal to 5. The branch operation is performed by simply setting
the PC to the address of the instruction at the top of the loop.