5 - Instruction Code - Addressing Modes
5 - Instruction Code - Addressing Modes
Instruction Codes
Program
set of instructions to specify the operations, operands and
the sequence by which processing has to occur.
Computer Instruction
• A binary code specifies a sequence of micro-operations for the
computer.
• Computer reads each instruction from memory and places it in a
control register.
• Then the control interprets the binary code of the instruction and
proceeds to execute it by issuing a sequence of micro-operations.
Instruction Codes
Instruction Code
• Group of bits that instruct the computer to perform a specific operation.
• Example Unique Binary code
is assigned to every
ADD 457 OpCode
15 12 11 0
Opcode Address
Instructions
(program)
Instruction Format
15 0 Operand
Binary Operand (data)
Processor Register
(accumulator or AC)
Stored Program Organization Contd..
Instruction Format
15 14 12 11 0
I Opcode Address
0 0 0 1 0 1 0 0 0 1 0 1 0 1 1 1
ADD 4 5 7
Direct & Indirect Addressing of Memory
Memory Memory
22 0 ADD 457 35 1 ADD 300
300 1350
457 Operand
1350 Operand
+ +
AC AC
Computer Registers
11 0
Program Counter(12)
PC Holds address of instruction
11 0
Address Register(12)
AR Holds address for memory
15 0
Instruction Register(16)
IR Holds instruction code
15 0
Temporary Register(16)
TR Holds temporary data
15 0
Data Register(16)
DR Holds memory operand
Computer Registers
15 0
Accumulator(16)
AC Processor Register
7 0
Output Register(8)
OUTR Holds output character
7 0
Input Register(8)
INPR Holds input character
Memory
4096 words
16 bits per word
S2
S1 Bus
Common Memory S0
4096 x 16 7
Address
Bus Write
AR
Read
1
System of
LD INR CLR
PC 2
LD INR CLR
Basic DR 3
LD INR CLR
Computer Adder
& Logic
E
AC 4
LD INR CLR
INPR
IR 5
LD
TR 6
LD INR CLR
OUTR
Clock
LD
Basic Computer Instruction Formats
01 01 01 01 Address
0 1 1 1 1
0 10 1
0 10 01 10 01 0 0 0 0 0
1 1 1 1 10 01 10 01 1
0 01 0 0 0 0 0 0
A sequence counter
•
IR has 3 parts
Op-code in bits 12-14 are decoded with a 3 x 8 decoder.
Bit-15 of the instruction is transferred to a flip-flop designated by
the symbol ‘I’.
Control Unit
▪ 8 outputs of the decoder => Designated by D0 through D7.
▪ Bits 0 through 11 are applied to the control logic gates.
▪ 4‐bit sequence counter can count in binary from 0 through 15. The
outputs of counter are decoded into 16 timing signals T0 through
T15.
▪ Sequence counter SC can be incremented or cleared
synchronously.
▪ Counter is incremented to provide the sequence of timing signals
out of 4 X 16 decoder.
▪ Counter is cleared to 0, causing the next timing signal to be T0.
Control Unit Example
Clock
CLR
SC
Control Unit
AR ← PC
IR ← M[AR], PC ← PC + 1
Execute
Execute
register- AR ← M[AR] Nothing
input-output
reference
instruction
instruction
SC ← 0
SC ← 0
Execute
memory-reference
instruction
SC ← 0
Interrupt Cycle
Instruction cycle = 0 = 1 Interrupt cycle
R
255 255
PC = 256 256
Main Program Main Program
1120 1120
I/O program I/O program
1 BUN 0 1 BUN 0
Design of AR ← PC AR ← 0, TR ← PC
Note: This is the internal storage format, usually invisible to the user
Cont..
• Big endian:
– Is more natural.
– The sign of the number can be determined by
looking at the byte at address offset 0.
– Strings and integers are stored in the same order.
• Little endian:
– Makes it easier to place values on non-word
boundaries, e.g. odd or even addresses
– Conversion from a 32-bit integer to a 16-bit integer
does not require any arithmetic.
Standard…What Standard?
• Intel (80x86), VAX are little-endian
• IBM 370, Motorola 680x0 (Mac), and most RISC systems are big-
endian
• Makes it problematic to translate data back and forth between
say a Mac/PC
• Internet is big-endian
– Why? Useful control bits in the Most Significant Byte can be
processed as the data streams in to avoid processing the rest
of the data
– Makes writing Internet programs on PC more awkward!
– Must convert back and forth
What is an instruction set?
• The complete collection of instructions that are
understood by a CPU
The physical hardware that is controlled by the
instructions is referred to as the Instruction Set
Architecture (ISA)
• The instruction set is ultimately represented in binary
machine code also referred to as object code
–Usually represented by assembly codes to human
programmer
Elements of an Instruction
• Op code : Do this
• Source Operand reference(s) : To this
• Result Operand reference(s) : Put the answer here
• Next Instruction : do this instruction next
Where are the operands?
• Main memory
• CPU register
• I/O device
• In an instruction itself
Y = (A-B) / (C + (D * E))
Let’s say that the default destination is the first operand in the
instruction
First operand might be a register, memory, etc.
Two Operand Instructions
Y = (A-B) / (C + (D * E))
• Second operand is left implicit; e.g. could assume that the second
operand will always be in a register such as the Accumulator:
Y = (A-B) / (C + (D * E))
LDA D ; Load ACC with D
MUL E ; Acc 🡨 Acc * E
ADD C ; Acc 🡨 Acc + C
STO R1 ; Store Acc to R1
LDA A ; Acc 🡨 A
SUB B ; Acc 🡨 A-B
DIV R1 ; Acc 🡨 Acc / R1
Add R4, R3
Load R3, R2
Direct Addressing Mode
• AKA Absolute Addressing mode.
• The instruction contains the address of the location in
memory where the value of the operand is stored.
• Advantage: simplest of all addressing mode.
• Disadvantage: provides a limited address space.
Cont..
• Effective address is the
address of memory
location.
• EA = A
Examples
Add R2, A
Store R2, B
Immediate Addressing Mode
• The value of the operand is explicitly mentioned in the
instruction.
• Effective address is not required as the operand is
explicitly defined in instruction.
• Advantage: memory reference is not required as the
value is explicitly present in the instruction
• Disadvantage: The instruction format provides a
limited size for the operand. So, the immediate
addressing mode has limited space for immediate
value.
Cont..
Example of immediate
addressing mode:
• Add R2, #100
• Store R2, 100H
Register Indirect Addressing Mode
Example
• Load R3, (R2) // Load R2, A
Index Addressing Mode
Helpful when the instructions in the program are accessing
the array or the large range of memory addresses.
EA is generated by adding a constant to the register’s
content.
The content of the register does not change.
Advantage: The index addressing mode provides flexibility
to specify memory locations.
Disadvantage: The index addressing mode is complex to
implement.
Index Addressing Mode
The symbolic representation of index
addressing mode is denoted as: X(R)
And the effective address is denoted
by EA = X + (R)
Example
Load R2, A
Load R3, (R2)
Load R4, 4(R2)
Load R5, 8(R2)
Load R6, 12(R2)
Relative Addressing Mode
In index addressing mode, there we were adding a
constant to the register content to refer the next operand
address.
In some computer instead of a register, the program
counter is used.
Representation of relative address mode is : X(PC)
EA = X + (PC)
Advantage: Relative addressing mode doesn’t require
memory references.
Auto Increment Addressing Mode
Load #800
Load 800
Load 800
Load R1[800]
Addressing Example
These are the values loaded into the accumulator for each
addressing mode.