Addressing modes

Posted in Computing, The processor

Addressing modes are the different ways the computer will get the memory location or address of a piece of data.

Immediate addressing

Immediate addressing is the simplest form of addressing where the data required is part of the instruction the computer is working on. The value is directly given to the processer, this is denoted by the #. For example:

LDA #20

This code will load the accumulator with the value 8.

Relative addressing

This form of addressing allows code to be relocatable, it is used to inform the computer where the next instruction is relative to the current one:

JMP +2

Will tell the processer to move 2 bytes ahead

Base register addressing

This is one of the more complex addressing modes. A base address is held in a register inside the processor. The instruction provides an offset which is added to the value in the base register giving the address:

LDA #20,Bx

This will add the value 20 to the value of the base register (Bx) to get the address.

Indexed addresssing

This is very similar to base register addressing - the key difference being the offset is stored in a register (index register) rather than the base address:

LDA 100,X

This code adds the value of the index register, X, to a base address (100) to calculate the address required.

Direct addressing

This addressing mode is where the instruction gives the address of the data directly:

LDA 20

This will load the accumulator with the contents of the memory location 20

Indirect addressing

Indirect addressing needs a bit of thinking about. In this addressing mode the address required is stored in another address, and it is that address which is referenced in the instruction. For example:

LDA (20)

This code will load the contents of the memory address which is stored in memory location 20.