Upload
jonah-palmer
View
216
Download
1
Embed Size (px)
Citation preview
Computer Architecture 計算機結構
1
Chapter 11Instruction Sets:
Addressing Modesand Formats
Ren-Jie Wang 王仁傑 , Ph.D. [email protected]
資訊館 7F 辦公室上課時間 : 星期三 13:25—16:10
Computer Architecture 計算機結構
2
Addressing Modes 定址模式 Immediate Addressing 立即定址 Direct Addressing 直接定址 Indirect Addressing 間接定址 Register Addressing 暫存器定址 Register Indirect Addressing 暫存間接器定址 Displacement Addressing 位移定址
Relative Addressing 相對定址 Base-Register Addressing 基底暫存器定址 Indexed Addressing 索引定址
Stack Addressing 堆疊定址
Computer Architecture 計算機結構
3
Immediate Addressing
Operand is part of instruction
Operand = address field
e.g. ADD 5 Add 5 to contents of accumulator ( AC←AC + 5 )
5 is operand
No memory reference to fetch data
Fast
Limited range ( why? )
Computer Architecture 計算機結構
4
Immediate Addressing Diagram
OperandOpcode
Instruction
運算碼( 指令 )
運算元( 資料 )
Computer Architecture 計算機結構
5
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 ( AC←AC + A )
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 ( why? )
Computer Architecture 計算機結構
6
Direct Addressing Diagram
Address AOpcode
Instruction
Memory
Operand
AADD
Computer Architecture 計算機結構
7
Indirect Addressing (1)
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
(A) : Content of location A or register A
Computer Architecture 計算機結構
8
Indirect Addressing (2)
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
Computer Architecture 計算機結構
9
Indirect Addressing Diagram
Address AOpcode
Instruction
Memory
Operand
Pointer to operand
(A)ADD
Computer Architecture 計算機結構
10
Indirect Addressing Diagram
Address AOpcode
Instruction
Memory
Operand
Pointer to operand
((A))ADD
Pointer to operand
Computer Architecture 計算機結構
11
Register Addressing (1)
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
Computer Architecture 計算機結構
12
Register Addressing (2)
No memory access
Very fast execution
Very limited address space
Multiple registers helps performance Requires good assembly programming or
compiler writing
C programming register int a;
c.f. Direct addressing
Computer Architecture 計算機結構
13
Register Addressing Diagram
Register Address ROpcode
Instruction
Registers
Operand
Computer Architecture 計算機結構
14
Register Indirect Addressing
C.f. 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
Computer Architecture 計算機結構
15
Register Indirect Addressing Diagram
Register Address ROpcode
Instruction
Memory
OperandPointer to Operand
Registers
(R)ADD
Computer Architecture 計算機結構
16
Displacement Addressing
EA = A + (R)
Address field hold two values A = base value 基底 R = register that holds displacement 位移 or vice versa 反之亦然
Computer Architecture 計算機結構
17
Displacement Addressing Diagram
Register ROpcode
Instruction
Memory
OperandPointer to Operand
Registers
Address A
+
Computer Architecture 計算機結構
18
Relative Addressing
A version of displacement addressing
R = Program counter, PC
EA = A + (PC) PC-relative
i.e. get operand from A cells from current
location pointed to by PC
c.f locality of reference & cache usage
Computer Architecture 計算機結構
19
Relative Addressing
Address AOpcode
Instruction
Memory
Operand+
PC
Pointer to Operand
Computer Architecture 計算機結構
20
Base-Register Addressing
A holds displacement
R holds pointer to base address
R may be explicit or implicit 外顯或隱含 e.g. segment registers in 80x86
Computer Architecture 計算機結構
21
Indexed Addressing
A = base
R = displacement
EA = A + (R)
Good for accessing arrays EA = A + (R)
(R) = (R) +1
Computer Architecture 計算機結構
22
Combinations
Pre-index 前索引定址模式 ( 先更新索引 , 再存取資料 ) 基底暫存器 A 的值與偏移量先做加減運算當索引位址 , 來存取資料 然後基底暫存器的值再更新成新的位址 EA = (A+(R))
ARM 指令 : LDR R0, [R1, #4]! ;R0:=[R1+4],
R1:=R1+4
Post-index 後索引定址模式 ( 先存取資料 , 後更新索引 ) 基底暫存器的值會先用來當所要存取的記憶體位址 存取資料後,基底暫存器的值再更新成新的位址 EA = (A) + (R)
ARM 指令 : LDR R0, [R1], #4 ;R0:=[R1], R1:=R1+4
Computer Architecture 計算機結構
23
Pre-index: EA = (A+(R))
Register ROpcode
Instruction
Memory
Operand
Displacement
Registers
Address A
+
Base
Pointer to Operand
Computer Architecture 計算機結構
24
Register ROpcode
Instruction
Memory
OperandDisplacement
Registers
Address A
+
Post-index: EA = (A) + (R)
Base
Computer Architecture 計算機結構
25
Stack Addressing
Operand is (implicitly) on top of stack
e.g. ADD Pop top two items from stack
and add
Textbook p. 398, problems #11.13
Computer Architecture 計算機結構
26
Computer Architecture 計算機結構
27
IA-32 (Pentium 4) RegistersIA-32 (Pentium 4) Registershttp://www.intel.com/design/processor/manuals/253665.pdf
Streaming SIMD Extensions MMX: SIMD instruction set
Computer Architecture 計算機結構
28
purposes in different
Computer Architecture 計算機結構
29
Computer Architecture 計算機結構
30
Pentium Addressing Modes
Virtual or effective address is offset into segment Starting address plus offset gives linear address
This goes through page translation if paging enabled
12 addressing modes available Immediate
Register operand
Displacement
Base
Base with displacement
Scaled index with displacement
Base with index and displacement
Base scaled index with displacement
Relative
Computer Architecture 計算機結構
31
Computer Architecture 計算機結構
32
Computer Architecture 計算機結構
33
Computer Architecture 計算機結構
34
Pentium Addressing Mode Calculation
Computer Architecture 計算機結構
35
Computer Architecture 計算機結構
39
Pentium Instruction Format
Computer Architecture 計算機結構
40
In-class exercise
Given the following memory values and a one-address machine with an accumulator, what values do the following instructions load into the accumulator? ( Textbook p. 397, problems #11.1 ) Word 20 contains 40 Word 30 contains 50 Word 40 contains 60 Word 50 contains 70
a. LOAD IMMEDIATE 20
b. LOAD DIRECT 20
c. LOAD INDIRECT 20
d. LOAD IMMEDIATE 30
e. LOAD DIRECT 30
f. LOAD INDIRECT 30
20 40
30 50
40 60
50 70
60
70
Computer Architecture 計算機結構
41
In-class exercise
Assume a stack-oriented processor that includes the stack operations PUSH and POP. Arithmetic operations automatically involve the top one or two stack elements. Begin with an empty stack. What stack elements remain after the following instructions are executed? ( Textbook p. 398, problems #11.13 ) PUSH 4 PUSH 7 PUSH 8 ADD PUSH 10 SUB MUL