william stallings computer organization and architecture 6 th edition chapter 11 instruction sets:...
TRANSCRIPT
William Stallings Computer Organization and Architecture6th Edition
Chapter 11Instruction Sets:Addressing Modesand Formats
Addressing Modes
Teknik Teknik Pengalamatan (Addressing) :
• Immediate• Direct• Indirect• Register• Register Indirect• Displacement (Indexed) • Stack
Immediate Addressing
• Operand is part of instruction• Operand = address field• Address field atau operand berisi Nilai
Konstan• e.g. ADD 5
—Add 5 to contents of accumulator—5 is operand
• No memory reference to fetch data• Fast• Limited range
Direct Addressing
• Address field contains address of operand• EA (Effective Address) adalah alamat
aktual dari lokasi yang berisi operand • Effective address (EA) = address 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• Tidak ada kalkulasi tambahan selain
effective address• Limited address space
Indirect Addressing (1)
• Pengalamatan tidak langsung• address field berisi alamat dari alamat
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 (2)
• Large address space • May be nested, multilevel, cascaded
—e.g. EA = (((A)))
• Multiple memory accesses to find operand• slower
Register Addressing (1)
• Operand is held in register• EA = R• Limited number of registers• Very small address field needed (Nama
register punya kode sendiri)—Shorter instructions—Faster instruction fetch
Register Addressing (2)
• 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;
• Hampir sama dgn Direct addressing
Register Indirect Addressing
• Hampir sama dengan indirect addressing• EA = (R)• Operand is in memory cell pointed to by
contents of register R• Large address space• fewer memory access than indirect
addressing
Register Indirect Addressing Diagram
Register Address ROpcode
Instruction
Memory
OperandPointer to Operand
Registers
Displacement Addressing
• EA = A + (R)• Address field hold two values
—A = base value—R = register that holds displacement—or vice versa
Displacement Addressing Diagram
Register ROpcode
Instruction
Memory
OperandPointer to Operand
Registers
Address A
+
Relative Addressing
• A version of displacement addressing• Dimana register R = Program counter, PC• EA = A + (PC)• i.e. get operand from A cells from current
location pointed to by PC• c.f locality of reference & cache usage
Base-Register Addressing
• Khusus di 80x86• A version of displacement addressing• A holds displacement• R holds pointer to base address• R may be explicit or implicit
Indexed Addressing
• A version of displacement addressing• A = base• R = displacement• EA = A + R• Good for accessing arrays
—EA = A + R—R++
Stack Addressing
• Operand is (implicitly) on top of stack• e.g.
—ADD Pop top two items from stackand add
Indexing
• Autoindexing— EA = A + (R)
(R) = (R) + 1
• Post Indexing: Indexing dilakukan setelah Indirection— EA = (A) + (R)
• PreIndexing : Indexing dilakukan sebelum Indirection—EA = (A + (R))
Auto-indexing addressing
LDR R0, [R1, #4]! @ R0=mem[R1+4]
@ R1=R1+4
LDR R0, [R1, ]!
R0
R1 +
No extra time; Fast;
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
• Pentium Addressing Mode— Immediate Operand = A—Register operand LA=R—Displacement LA=(SR)+A—Base LA=(SR)+(B)—Base with displacement LA=(SR)+(B)+A—Scaled index with displacement LA=(SR)+(I)xS
+ A—Base with index and displacement LA=(SR)+(B)+
(I)+A—Base scaled index with displacement LA=(SR)+(I)xS+
(B)+A—Relative LA=(PC)+A
• LA =Linear Address• (X) = Content of X• SR = segment register• PC=Program Counter• A =Content of an address field in the
instruction• R=Register• B= Base Register• I = Index Register• S = Scaling Factor
• Scaling factor 2 : Array /Data 16-bit integer
• Scaling factor 4 : Array / Data 32-bit integer atau floating point number (single precision)
• Scaling factor 8 : Array / Data double precision floating point
PowerPC Addressing Modes• PowerPC => RISC• RISC pengalamatannya lebih sederhana dari CISC• Mode Algorithm
Load/Store AlgorithmIndirect EA = (BR) + DIndirect Indexed EA = (BR) + (IR)
Branch AddressingAbsolute EA = IRelative EA = (PC) + IIndirect EA = (L / CR)
Fixed Point Computation
Register EA = GPRImmediate Operand = I
Floating PointRegister EA = FPR
PowerPC Addressing Modes
• EA = Effective Address• (X) = Content of X• BR = Base Register• IR = Index Register• L/CR = Link or Count Register• GPR = General Purpose register• FPR = Floating Point Register• D = Displacement• I = Immediate Value• PC = Program Counter
Instruction Formats
• Format Instruksi mendefinisikan :— Layout of bits in an instruction— Includes opcode (Harus ada OpCode)— Includes (implicit or explicit) operand(s)— Usually more than one instruction format in
an instruction set
Instruction Length
• Panjang Instruksi mempengaruhi :— Memory size (Kapasitas memori)— Memory organization— Bus structure— CPU complexity— CPU speed
• Trade off between powerful instruction and saving space
• Programmer menginginkan lebih banyak:— Opcode— Operand— Addressing mode
Allocation of Bits
• Faktor-faktor yang menentukan penggunaan addressing bit:— Number of addressing modes— Number of operands— Register versus memory— Number of register sets— Address range— Address granularity (alamat mengacu byte,
word, dll)