COA - Chapter # 8
COA - Chapter # 8
Immediate
Direct
Indirect
Register
Register Indirect
Displacement (Indexed)
Stack
Instruction
Opcode Operand
Instruction
Opcode Address A
Memory
Operand
accumulator
Advantage:
Large address space available
2n where n = word length
Disadvantage:
Instruction execution requires two memory references to
fetch the operand
One to get its address and a second to get its value
Hence slower
May be nested, multilevel, cascaded
e.g. EA = (((A)))
Instruction
Opcode Address A
Memory
Pointer to operand
Operand
Instruction
Opcode Register Address R
Registers
Operand
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
Instruction
Memory
Registers
Instruction
Opcode Register R Address A
Memory
Registers
A holds displacement
R holds pointer to base address
R may be explicit or implicit
e.g. segment registers in 80x86
Exploits the locality of memory references
Convenient means of implementing segmentation
In some implementations a single segment base register is
employed and is used implicitly
In others the programmer may choose a register to hold
the base address of a segment and the instruction must
reference it explicitly
Chapter # 8 Computer Organization & Architecture 18
Indexed Addressing
S H E H E R YAR MALI K
Postindexing
Indexing is performed after the indirection
EA = (A) + (R)
Preindexing
Indexing is performed before the indirection
EA = (A + (R))
Preindex
Memory address is formed as for offset addressing
Memory address also written back to base register
So base register value incremented or decremented by offset value
Postindex
Memory address is base register value
Offset added or subtracted
Result written back to base register
Base register acts as index register for preindex and postindex
addressing
Offset either immediate value in instruction or another
register
If register scaled register addressing available
Offset register value scaled by shift operator
Instruction specifies shift size
Address modification
Base, displacement
Base, index, displacement
Instruction prefixes
Instruction prefix
The instruction prefix, if present, consists of the LOCK prefix or one
of the repeat prefixes
The LOCK prefix is used to ensure exclusive use of shared memory in
multiprocessor environments
The repeat prefixes specify repeated operation of a string, which
enables the x86 to process strings much faster than with a regular
software loop
There are five different repeat prefixes: REP, REPE, REPZ, REPNE, and
REPNZ
Segment override
Explicitly specifies which segment register an instruction should use,
overriding the default segment-register selection generated by the
x86 for that instruction
Operand size
An instruction has a default operand size of 16 or 32 bits, and the
operand prefix switches between 32-bit and 16-bit operands
Address size
The processor can address memory using either 16- or 32-bit
addresses
The address size determines the displacement size in instructions
and the size of address offsets generated during effective address
calculation
Opcode
The opcode field is 1, 2, or 3 bytes in length
The opcode may also include bits that specify if data is
byte- or full-size (16 or 32 bits depending on context),
direction of data operation (to or from memory), and
whether an immediate data field must be sign extended
ModR/M
This byte provide addressing information
The ModR/M byte specifies whether an operand is in a
register or in memory
If it is in memory, then fields within the byte specify the
addressing mode to be used
Chapter # 8 Computer Organization & Architecture 43
x86 Instruction Format
S H E H E R YAR MALI K
SIB
Certain encoding of the ModR/M byte specifies the inclusion of
the SIB byte to specify fully the addressing mode
The SIB byte consists of three fields
Scale field (2 bits) specifies the scale factor for scaled indexing
Index field (3 bits) specifies the index register
Base field (3 bits) specifies the base register
Displacement
When the addressing-mode specifier indicates that a
displacement is used, an 8-, 16-, or 32-bit signed integer
displacement field is added
Immediate
Provides the value of an 8-, 16-, or 32-bit operand
Chapter # 8 Computer Organization & Architecture 44
ARM Instruction Formats
S H E H E R YAR MALI K