Instruction Sets: Characteristics and Functions Addressing Modes and Formats
Instruction Sets: Characteristics and Functions Addressing Modes and Formats
CE204 Computer Architecture and Organization by Dr. Ahmet ZKURT William Stallings, Computer Organization and Architecture 6th Edition
1
Instruction Representation
In machine code each instruction has a unique bit pattern For human consumption (well, programmers anyway) 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 storage (main memory) Data movement (I/O) Program flow control
3
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 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 1 address Implicit second address Usually a register (accumulator) Common on early machines 0 (zero) addresses All addresses implicit Uses a stack e.g. push a push b add pop c c=a+b
Types of Operand
Addresses Numbers Integer/floating point Characters ASCII etc. Logical Data Bits or flags
(Aside: Is there any difference between numbers and characters? Ask a C programmer!)
10
11
Types of Operation
Data Transfer Arithmetic Logical Conversion I/O System Control Transfer of Control
12
Branch Instruction
13
14
Use of Stack
15
Byte Order
What order do we read numbers that occupy more than one byte e.g. (numbers in hex to make it easy to read) 12345678 can be stored in 4x8bit locations as follows Address 184 185 186 186 Value (1) 12 34 56 78 Value(2) 78 56 34 12
16
17
18
19
StandardWhat Standard?
Pentium (80x86), VAX are little-endian IBM 370, Motorola 680x0 (Mac), and most RISC are big-endian Internet is big-endian Makes writing Internet programs on PC more awkward! WinSock provides htoi and itoh (Host to Internet & Internet to Host) functions to convert
20
Addressing Modes
Immediate Direct Indirect Register Register Indirect Displacement (Indexed) Stack
21
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
22
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
Memory
Instruction
Opcode Address A
Operand
23
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 Large address space 2n where n = word length May be nested, multilevel, cascaded e.g. EA = (((A))) Draw the diagram yourself Multiple memory accesses to find operand Hence slower
24
Operand
25
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 No memory access Very fast execution Very limited address space Multiple registers helps performance Requires good assembly programming or compiler writing N.B. C programming register int a; c.f. Direct addressing
26
Operand
27
Registers
Pointer to Operand
Operand
28
Displacement Addressing
EA = A + (R) Address field hold two values A = base value R = register that holds displacement or vice versa
Instruction
Opcode Register R Address A
Memory
Registers
Pointer to Operand
Operand
29
31
32
33
34
Allocation of Bits
Number of addressing modes Number of operands Register versus memory Number of register sets Address range Address granularity
36
37
38
39
40
41
42