Instruction Set
A collection of commands that the processor can understand and execute.It can be in the form of binary or assemble code.
Element of machine instruction.
Opcode (Operation Code) : specifies the operation that need to be done.
e.g : ADD,SUB,MUL,DIV
Source Operand Reference : Any operation will need one or more operand/variable/inputs.
e.g : Y = B - C.B and C are operand.
Operands can be perform the I/O device as keybord,registe
or main memory.
Result Operand Reference : Where to restore the result of the operation.
Next Instruction Reference : Tell the processor to fetch the next instruction once the current
instruction is completed.
Instruction Cycle State diagram
INSTRUCTION
REPRESENTATION
·
Instructions are represented by a sequence of
bits.
·
These bits are then divided into different
fields/sections.
·
Opcodes are represented using abbreviations
called mnemonics.
·
Example : ADD, SUB. LOAD.
·
ADD A, B
------- Get the value in
address B to be added with the value in address A and
store the answer in address A
INSTRUCTION TYPES
·
In
a typical instruction ----- X = X + Y, what is does is, it instructs the
processor to add the values in address Y to the value stored in address X and
keep the result in address X.
·
So
basically the steps are:
1.
Load
values to the register from memory location X.
2.
Add
content of address Y to that register.
3.
Store
the result of that register to memory location X.
·
So
based on the steps above, we can state the types of instruction required for a
general instruction.
1.
Data
processing
§
To
do arithmetic and logic operations
2.
Data
Storage
§
Take
data from memory and store in registers and vice versa
§
Take
data from I/O devices and store in memory or registers and vice versa.
3.
Data
movements
§
Move
data from devices to memory and vice versa.
4.
Control
§
Testing
data and branching of instruction.
§
Example
: JUMP, LOOP
NUMBER OF
ADDRESSES IN AN INSTRUCTION
· One
way of describing a processor’s architecture is in terms of the number of
addresses contained in each instruction.
· What
is the maximum number of addresses needed for an instruction? Well…it depends
on what operation needs to be done. Different processors might have different
addresses for different reasons.
· Usually
arithmetic and logic operations require the most operands. So for a simple
calculation like X = A + B, 2
addresses are needed for the operands and 1 address is required to keep the
result. Another address will be required to keep the address of the next
instruction. So in this case, 4 address instructions are needed.
· But
then again…it all depends on the architecture of the processor.
· Most
architecture will have 1, 2 or 3 addresses which is sufficient to do all sorts
of
operations.
· What
is the implication of having lesser or more addresses in an instruction?
o
Lesser
addresses:
§
Need
lesser registers.
§
Instruction
looks much for simpler and less complex.
§
Need
more lines of instruction for a complete program thus making the program
longer.
§
Faster
in terms of fetching and executing instructions.
o
More
addresses:
§
Need
more registers.
§
Instructions
become more complex and longer.
§
Fewer
lines of instructions are required thus making the program shorter.
§
Takes
longer time to fetch and execute each instruction.
Utilization of
Instruction Addresses (Nonbranching Instructions)
AC
= Accumulator
T
= Top of stack
(T-1)
= Second element of stack
A,
B, C = Memory or register locations
INSTRUCTION SET DESIGN
·
Design
of the instruction set is important and complex because it affects many parts
of the computer system.
·
Programmers
use this instructions set to control the processor (tell the processor what to
do).
·
So
the instruction set must be designed in such a way that it can be used easily
to write commands.
·
Designs
issues to consider:
1. Operation
repertoire
§
List
of operations that can be done.
§
List
of opcodes and what each opcode can do.
§
How
complex are the operations?
2. Data
type
§
Type
of data that can be operated on.
§
Integers,
floating point numbers, characters. Boolean values.
3. Instruction
format
§
Length
of the instruction, how many bits?
§
How
many addresses required? 0? 1? 2? 3?
§
Each
section/field of the instructions requires how many bits?
4. Registers
§
Numbers
of registers available for use.
§
Which
operation can be performed on which registers?
5. Addressing
mode
§
Direct
addressing? Immediate addressing?
TYPES OF OPERANDS
·
Machine
instructions operate of data
·
General
categories of data:
1. Addresses
§
Considered
as unsigned integers.
2. Numbers
§
Integers,
binary, floating point, hexadecimal, octal.
3. Characters
§
String/text
and characters values are easily understood by humans, but not by a machine. So
reference codes like ACSII are used to represent characters and symbols.
4. Logical
§
Having
values of 1 or 0 to denote true or false values.
§
Common
naming convention is flag.
TYPES OF OPERATIONS
·
Different
machines use different opcodes. But there are many general ones that are used
by majority of the processors.
·
General
categories of operations:
·
Data
transfer.
§
To
more data from one location to another.
§
Example
: Move, store, load, set, push, pop
·
Arithmetic.
§
To
do calculations.
§
Example
: Add, Sub, Mul, Div, Increment, Decrement
·
Logical.
§
Example
: And, Or, Not, Shift, Rotate.
·
Transfer
of Control.
§
Example:
When an interrupt happens, the program will jump to another section to handle
the interrupt.
§
Jump,
return, skip, wait.
·
Input/Output
§
Getting
input from keyboard or to display results onto the monitor.
§
Input(Read),
output(write)
·
Conversion
§
Example:
To change format --- hex to binary
·
System
Control
§
Instructions
reserved only for OS to use.
§
Maybe
to set registers to Read Only mode.
§
Maybe
to set only certain operations can access certain registers.
INSTRUCTION FORMATS
·
Instruction
format defines the layout of bits in an instruction in terms of its basic
fields.
·
An
instruction format must include opcode, implicitly or explicitly with 0 or more
operands which is being referenced using the addressing modes.
·
Addressing
mode for each operand must be clearly indicated.
·
Most
instruction sets might employ more than one instruction format.
·
Important
design issues:
1. Instruction
Length:
§
If
affects and affected by:
·
Memory
size.
o
Programmers
would want to design shorter programs. This requires instructions with more
opcodes, more operands and more addressing modes. All this requires more memory
space.
·
Memory
organization.
o
How
the addresses and data are organized in the memory. Usually it will be organized
in terms of bytes.
o
Data
are stored in multiples like 8 bits, 16 bits, 32 bits.
·
Bus
structure
o
Instruction
length should be equal to the memory transfer length which is based on the bus
structure. Otherwise instruction might be broken down and in certain cases lead
to data loss.
·
CPU
complexity and speed
o
Length
of the instruction should be designed in a way that the processor can fetch and
execute without any delay. It will be a problem if the processor is slow in
executing the instruction but fast in fetching the instruction.
o
But
these can be solved by using the many memory management options available like
cache.
2. Allocation
of bits:
Another important issue to
consider is how to allocate the bits in a desired instruction format. Factors
to be considered when determining the use of addressing bits:
§
Number
of addressing modes.
·
Different
addressing modes requires different number of bits.
·
Some
addressing modes can be incorporated into the opcode implicitly/hidden.
·
Some
might need extra bits to determine which type of addressing mode is required.
§
Number
of operands.
·
When
more operand is included into an instruction, it results in the instruction
getting longer. This means that more bits is required.
§
Register
versus Memory
·
If
more registers are used, number of bits required is lesser. This is because
registers has limited range compared to memory.
·
But
it all depends on the number of usable and available registers are in the
processor.
§
Number
of register sets
·
Most
machines have 1 set of general purpose registers which contain 32 or more
registers. It can be used to store data and address.
·
Some
architectures have more than 1 set of general purpose registers.
·
More
sets means shorter instructions and results in smaller bits required.
§
Address
range.
·
Different
addressing modes require different addressing bits.
·
Example:
Direct addressing has limited number of address space. But Displacement
addressing has requirements for 2 address When more operand is included into an
instruction, it results in the
§
Address
granularity.
·
When
addressing the memory, they are being reference by bytes of words. Byte
addressing is more convenient for the programmer because characters are
represented in bytes but this kind of fixed sized memory requires more address
bits