You are on page 1of 48

Computer Architecture and

Organization

Dr. Khawar Khurshid


Spring ‘20
Instruction Set
Addressing Modes
Design Decisions
 Instruction formats
 Length of op code field
 Number of addresses

 Operations
 How many ops?
 Which ops?

 Data types

 Addressing modes
What is an Instruction Set?

 The complete collection of instructions


that are understood by a CPU

 Usually represented by assembly codes


Elements of an Instruction

 Operation code (Op code)


 Do this
 Source Operand reference
 To this
 Result Operand reference
 Put the answer here
Types of Operand

 Addresses
 Numbers
 Logical Data
Instruction Representation

 In machine code each instruction has a


unique bit pattern
 For users a symbolic representation is
used
 e.g. ADD, SUB, LOAD
 Operands can also be represented in this
way
 ADD A,B
Simple Instruction Format
Instruction Types

 Data processing
 Data movement
 Program flow control
Number of Addresses

 3 addresses
 2 addresses
 1 address
 0 address
Number of Addresses

 3 addresses
 Operand 1, Operand 2, Result
 c = a + b;
 Not common
 Needs very long instructions to hold
everything
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
Number of Addresses

 1 address
 Implicit second address
 Usually a register (accumulator)
Number of Addresses

 0 (zero) addresses
 All addresses implicit
 Uses a stack
 e.g. push a
 push b
 add
 pop c

 c=a+b
How Many Addresses

 More addresses
 More complex instructions
 More registers
 Fewer instructions per program

 Fewer addresses
 Less complex instructions
 More instructions per program
 Slower execution of program
Types of Operation

 Data Transfer
 Arithmetic
 Logical
 Transfer of Control
Types of Operations

• Data Transfer  Specify


• Arithmetic  Source
• Logical  Destination
• Transfer of Control
Types of Operations

• Data Transfer • Add, Subtract,


• Arithmetic • Multiply, Divide
• Logical • May include
• Transfer of Control —Increment (a++)
—Decrement (a--)
—Negate (-a)
Types of Operations

• Data Transfer
• Arithmetic • Bitwise operations
• Logical • AND, OR, NOT
• Transfer of Control
• Shift left, right
Types of Operations

• Data Transfer
• Arithmetic
• Logical
• Transfer of Control
• Branch
— e.g. branch to x if
result is zero
• Skip
— e.g. increment and skip
if zero
• Subroutine call
Branch Instruction
Nested Procedure Calls
Use of Stack
Data Types

 8 bit Byte
 16 bit word
 32 bit double word
 64 bit quad word
 Floating Point data
 Addressing through 8 bit unit
Byte Order

 What order do we read numbers that


occupy more than one byte

 87654321 can be stored in 4x8bit


locations as follows
Byte Order (example)

 Address Value (1) Value (2)


 184 87 21
 185 65 43
 186 43 65
 186 21 87

 i.e. read top down or bottom up


Byte Order Names
 The problem is called Endian
 The system on the left has the most significant
byte in the lowest address
 This is called big-endian
 The system on the right has the least
significant byte in the lowest address
 This is called little-endian
Example
Addressing Modes and
Formats
Addressing Modes

 Immediate
 Direct
 Indirect
 Register
 Register Indirect
 Displacement
 Stack
Immediate Addressing

 Operand is part of instruction


 Operand = address field
 e.g. ADD 5
 Add 5 to contents of accumulator
 5 is operand
 No memory reference to fetch data
 Fast
 Limited range
Immediate Addressing

Instruction
Opcode Operand
Direct Addressing

 Address field contains address of operand


 Effective address (EA) = address field (A)
 e.g. ADD A
 Add contents of cell A to accumulator
 Look in memory at address A for operand
 Single memory reference to access data
 No additional calculations to work out
effective address
 Limited address space
Direct Addressing

Instruction
Opcode Address A
Memory

Operand
Indirect Addressing

 Memory cell pointed to by address field


contains the address of (pointer to) the
operand
 EA = (A)
 Look in A, find address (A) and look there for
operand
 e.g. ADD (A)
 Add contents of cell pointed to by contents
of A to accumulator
Indirect Addressing

 Large address space


 2n where n = word length
 Multiple memory accesses to find
operand
 Hence slower
Indirect Addressing
Instruction
Opcode Address A
Memory

Pointer to operand

Operand
Register Addressing

 Operand is held in register named in


address filed
 EA = R
 Limited number of registers
 Very small address field needed
 Shorter instructions
 Faster instruction fetch
Register Addressing

 No memory access
 Very fast execution
 Very limited address space
 Multiple registers helps performance
Register Addressing

Instruction
Opcode Register Address R
Registers

Operand
Register Indirect Addressing

 EA = (R)
 Operand is in memory cell pointed to by
contents of register R
 Large address space (2n)
 One fewer memory access than indirect
addressing
Register Indirect Addressing

Instruction
Opcode Register Address R
Memory

Registers

Pointer to Operand Operand


Displacement Addressing

 EA = A + (R)
 Address field hold two values
 R = register that holds the base address
 A = displacement
Displacement Addressing

Instruction
Opcode Register R Address A
Memory

Registers

Pointer to Operand + Operand


Relative Addressing

 A version of displacement addressing


 R = Program counter
 EA = A + (PC)
 i.e. get operand from A cells from current
location pointed to by PC
Base Addressing

 A version of displacement addressing


 R = A dedicated Base Register
 EA = A + (B)
 i.e. get operand from A cells from
location pointed to by B
Stack Addressing

 Operand is (implicitly) on top of stack


 e.g.
 ADD Pop top two items from stack
and add
Any Queries?

Thank You

You might also like