What is instruction set?
• The complete collection of instructions that
are understood by a CPU is called
Instruction set.
• It has its own formats and elements
• Operation code (Opcode)
ADD, SUB, MUL, DIV, LOAD, STORE
• Source operand reference
Address of opcode e.g. register, memory location
• Result operand reference
Put the result here
Instruction format
• An instruction is normally made up of a
combination of an operation code and some way
of specifying an operand.
• Most commonly by its location or address in
memory
• Some operation codes deal with more than one
operand; the locations of these operands may be
specified using any of the many addressing
schemes.
Instruction format
A computer will usually have a variety of instruction
code format.
•The control unit understand each instruction code
and provide the necessary control function.
•The bits of the instruction are divided into groups
called fields.
Instruction format
The most common fields in instruction format are:
Operation code (opcode): specify operation to be
performed
Address field: specifies memory or processor address
Operands residing in memory are specified with their
memory address
•Operands residing in processor registers are specified
with a register address (a CPU with 16 processor registers
R0 to R15 will have a register address field of four bits)
Mode field: specifies the addressing mode
Instruction format
• Most computers fall into one of three type of CPU
organization:
[Link] accumulator: all operations are performed with an
implied accumulator register.
•The instruction format uses one address field
[Link] register: the instruction format needs three
register address fields.
[Link]: PUSH and POP instructions require an address
field. Operation type instructions do not need an address
field
•This is because the operation is performed on the two items
that are on top of the stack
Instruction Types
• Instructions, of most modern computers, may be
classified into the following groups:
1. Data transfer
• Specifies: Source and destination (memory,
register, stack), amount of data
• May be different instructions for different (size,
location) movements
Example MOV, LOAD,STORE,PUSH,POP
• LOAD: copy data to a register from memory
• STORE: copy data to a memory location from a
register
• MOV : data can be move from memory location to
register or from register to main memory
• PUSH: insert data into Stack
• POP: remove data from stack
2. Input/Output
May be specific instructions, May be done using
data movement instructions (memory mapped
I/O)
Example: Separate I/O, space input/output
3. Arithmetic
• Add, Subtract, Multiply, Divide
(ADD, SUB, MUL, DIV)
• May also include
Absolute (|a|)
Increment (a++)
Decrement (a--)
Negate
4. Logical
• Bitwise operations:
AND, OR, NOT, XOR, TEST, CMP, SET
• Shifting and rotating functions
e.g.
Arithmetic right shift(ARS): Division and truncation for
odd numbers
Arithmetic left shift(ALS): Multiplication without
overflow
[Link]-control instructions
Control the sequences of program executions
Unconditional branch
Jump % branch to the label (eg goto)
Conditional branch
• if, else… if, loops
Subroutine/function call and return
CALL SUB % push PC; branch to SUB
RET -return % pop PC
Interrupt-handling
TRAP % generate an internal interrupt
5. Other eg. Halt to shutdown the computer
Instruction length
• Affected by and affects:
Memory size
Memory organization - addressing
Bus structure, e.g., width
CPU complexity
CPU speed
• Trade off between powerful instruction list and
saving space
Number of Addresses
• 3 addresses
– Operand 1, Operand 2, Result
– a = b + c;
– May be a forth - next instruction (usually implicit)
– Not common
– Needs very long words to hold everything
Example: c=a+b
ADD c,a,b; M[c]a+b
Number of Addresses
• 2 addresses
– One address doubles as operand and result
–a=a+b
– Reduces length of instruction
– Requires some extra work
• Temporary storage to hold some results
Example: c = a + b
MOV R1,a ; R1M[a]
ADD R1,b ; R1R1+M[b]
MOV c,R1 ; M[c]R1
Number of Addresses
• 1 address
– Implicit second address
– Usually a register (accumulator)
– Common on early machines
Example : c = a + b
LOAD a ; AcM[A]
ADD b ; AcAc+M[B]
STORE C ; M[c]Ac
Number of Addresses
• 0 (zero) addresses
All addresses implicit
Uses a stack
e.g. c = a + b
push a
push b
add
pop c