Addressing Modes
- Relative Addressing and Branches
- Indirect Addressing
- Indexed Addressing
- 6502 addressing modes
- 6800 addressing modes
- 8085 addressing modes
- x86 addressing modes
Relative Addressing
- A compiler or assembler produces code
- sometimes (especially without virtual memory) we want to be able
to put this code at different places in memory
- sometimes we even want to move it around at runtime, to make room
for other things (overlays)
- this is easiest if all references to labels in the code are relative
to the PC/IP
- this also tends to save memory, since most jumps are to nearby
locations and the offset can be represented with one byte
Relative Branches
- a relative branch always counts from the instruction following
the branch
- that is because the PC/IP is incremented before the instruction execution
0123 BRA 02
0124 ! offset byte
0125 BRA FE ! infinite loop
0126 ! offset byte
0127 label: INC ! target of first branch
Indirect Addressing
- in direct addressing, the memory location of the operand
is in the two/four bytes following the opcode
- in indirect addressing, the memory location of a pointer
to the operand is in the two/four bytes following the opcode
- for example, the following code jumps to the location pointed
to by the two bytes at location 100016:
0123 JMP (1000)
- in register indirect addressing, a register is used as a pointer
Indexed Addressing
- Index register
- constant (immediate) offset
- the two are added together to give the effective address
- the operand is found at the effective address
- 6800 example using index register X with offset 19:
LDAB 19,X
6502 Addressing Modes
- relative addressing only available for branches
- indirect addressing only available for JMP instruction (JMP has
absolute and indirect modes)
- in-class exercise: what is the indirect jump useful for?
More 6502 Addressing Modes
- zero page, X (Y): 8-bit offset added to 8-bit X (Y) register,
truncated to 8 bits
- absolute, X (Y): 16-bit offset added to 8-bit X (Y) register
truncated to 16 bits
- indirect indexed LDA (aa), Y: aa and aa+1
contain a 16-bit pointer which is added to Y to give the effective
address
- indexed indirect LDA (aa,X): aa+X and aa+X+1
contain a 16-bit pointer to the effective address
- in-class exercise: find a use for indirect indexed and a use
for indexed indirect
6800 and 8085 Addressing Modes
- 6800 relative addressing: jumps and subroutine calls
- 6800 indexed addressing LDAA aa, X: the effective address
is the 16-bit sum aa + X (index registers on 6800 are 16 bits)
- 8085 register indirect: 16-bit register pair, usually HL, holds
the effective address
x86 Addressing Modes
- register indirect addressing MOV AL, [BX]: registers
BP (uses stack segment), BX, SI, DI (data segment)
EA is the contents of the register (plus segment)
- register relative addressing MOV AL, [BX + 89AB]:
EA is the 16- (32-) bit sum of the contents of BX
and the constant offset (plus segment)
- program relative addressing: JMP 333 at location 300
has offset 31
- program indirect addressing: JMP [BX+100] jumps to
the address found at memory location pointed to by BX
- base plus index addressing: MOV AX, [BX+DI]
- base relative plus index addressing: MOV AX, [BX+SI+10]