3D1-Microprocessor Systems 1

Lecture 7: Addressing Modes

As well as hardware for executing instructions, a processorneeds hardware to access data.Principally, hardware is needed to read and write data to and from registersand memory.The capabilities of the accessing hardware are reflected in theprocessor’s instruction set in the so-called addressing modes.Hence, the term ‘addressing modes’ refers to the allowable ways inwhich the processor instructions can refer to data.CISC processors tend to have many different addressing modes whilst RISC processors tend to have a very small number of addressingmodes. In this lecture, we will introduce the three fundamental addressing modes on the 68000:immediate, absolute and indirect. We will also look at some variations of the immediate and direct modes.

Learning Outcomes:

On completion of this lecture, you will be able to:

  • Distinguish between immediate, direct and indirect addressing modes;
  • Select an appropriate addressing mode for a given instruction;
  • Implement the following addressing modes: immediate, quick immediate, data register direct, address register direct, absolute memory long, absolute memory short and address register indirect.

7.1Categories of addressing modes

You select an appropriate addressing mode for a piece of datadepending on how much you know about the data item itselfwhen you’re writing the program:

  • If you know the value of the data, use an ‘Immediate AddressingMode,’ signified by a # sign.
  • If you know the location of the data, use a ‘Direct AddressingMode.’
  • If you know how to calculate the location of the data or howto calculate the data itself, use an ‘Indirect Addressing Mode.’

Level of Knowledge of Data / Kind of Addressing Mode
Value can be known at assembly time / Immediate Mode
(Immediate Values aresometimes called ‘Literals’)
Location can be known at assembly time / Direct Mode
Location or value can be calculated at runtime / Indirect Mode

The 68000 has fourteen addressing modes and we will look at eleven of them through the course:

  • Two immediate modes;
  • Four direct modes;
  • Five indirect modes;
  • The remaining three are a special case of the indirect modes.

7.2Immediate Addressing Modes

We have already encountered immediate addressing in which the actual operand is supplied with the instruction. We will describe two types of immediate addressing modes: immediate and quick immediate.

7.2.1Immediate

  • Specify the operand as a byte, word or longword item. Allsensible values permitted of 8, 16 or 32 bits asappropriate.
  • Only values known at assembly time allowed e.g.

#21,

#$60FA,

#$12234-$24

#(567*$ab)-’x’

  • These are not permissible as immediate operands:

#61+D0

#$74+(A4)

Why?

7.2.2Quick Immediate Instructions

Some instructions and operands occur very frequently in the instruction execution stream, and some of these are speeded up by making the instruction shorter:

  • MOVE has a MOVEQ;
  • ADD and SUB have ADDQ and SUBQ.

Each of these instructions expects a ‘quick immediate’ operandwith a restricted range of values.

MOVEQ (Move Quick):

  • Allows eight bits to represent the immediate data.
  • The destination must be a data register.
  • The eight bit data is sign-extended to fill all 32 bits of the dataregister.

ADDQ and SUBQ(Add and Subtract Quick)

  • Allows three bits to represent the immediate data, which ismapped to the values 1 to 8 (not 0 to 7!)
  • Size of the operation can be specified to byte, word, long
  • The destination is not restricted to be a data register.
  • The three bit data is sign-extended to fill the size of the operationspecified.

7.3Direct Addressing modes

If the Operand is in a Register (‘Register Direct’) you can use:

  • Data Register Direct
  • Address Register Direct

If the Operand is in Memory (‘Memory Direct’) you may use:

  • Absolute Memory Short
  • Absolute Memory Long

7.3.1Register Direct

  • Just specify the register on its own, no brackets or anything. E.g. A4, D3
  • Address Register Direct An
  • Data Register Direct Dn
  • Memory Direct

Memory Direct modes are used to specify where an operand isin memory.

  • Just specify the memory location ‘directly,’ e.g.

21,

$12FA,

$6534-21+’a’

  • Notice the syntactic (i.e. grammatical) difference between immediate and direct: what is it?

Address Space

The 68000 processor family, being a fully 32-bit family, has a 32-bit address space (i.e. 232 distinct byte locations in memory.)

The 68000 itself only uses 24 bits of the available address space.This is a hardware restriction of the 68000 itself. To writeportable code, write for a 32-bit address space.

Two Memory Direct Modes

For reasons that are perhaps partly historical and partly speedmotivated, the 68000 has:

  • a 16-bit direct addressing mode called Absolute Memory Short along with
  • a 32-bit direct addressing mode called Absolute Memory Long

A 16-bit address is an address represented by only 16 bits, thusonly 216 (i.e. 65536) distinct locations can be specified.

Absolute Memory Long

  • This is just the memory referencing addressing mode you wouldexpect in a 32-bit machine. You can specify any address in the 32-bit address space, e.g.

$f0463047,

$1048-21+’a’

etc.

  • As with immediate modes, you can use any expression that maybe evaluated at assembly time as an absolute memory reference.
  • The address is represented in the instruction as a 32-bit item.

Absolute Memory Short

To save space in an instruction, an abbreviated address can bestored in 16 bits. It is sign-extended to the full 32 bits whenneeded. This means the range of addresses is limited to:

$00000000 – $00007FFF, $FFFF8000 – $FFFFFFFF,i.e. the bottom 32768 and the top 32768 of addresses in the full 32-bit address space

Because it is only 16 bits, the instruction of which it is part isfetched faster.

7.4Address Register Indirect

We will look at five indirect addressing modes in the course, butnow we’ll just look at one -- ‘Address Register Indirect.’You can make up the functionality of most the other indirect addressing modes from this; they are provided for convenienceand speed.

Motivation for Indirection

  • To use a number as an address;
  • In other words, to be able to calculate the location of something, and then, crucially, to be able to use it as an addressand reference something with it.

The 68000 has eight address registers, A0 to A7, which are exploited in the address register indirect addressing. In this indirect addressing mode, the address of an operand is found in an address register, rather than in the instruction. Address register indirect is indicated to the assembler by enclosing an address register in round parentheses.

e.g: CLR (A0)means: clear the contents of the memory location whose address is the contents of address register (A0).

To access an operand two accesses must be made: the first is to the address register to find the actual address of the operand and the second is to the operand itself.

Since the registers are on the chip along with the CPU, little time is lost reading their contents to locate the operand in memory.

7.5Conclusion

Addressing modes are concerned with how an operand is located by the CPU.

Immediate addressing, also known as literal addressing, allows you to specify a constant as an operand: the value following the instruction op-code is the actual operand itself. In 68000 assembly language, the symbol # precedes the operand to indicate immediate addressing. Immediate addressing is used whenever the value of the operand is known at the time the program is written.

In direct, also called absolute, addressing the operand field of the instruction provides the address of the operand in memory. Direct addressing is used whenever the address of a variable is constant.

Address register indirect addressing uses an address register to point at the location of an operand in memory. This addressing mode is indicated to the 68000 assembler by enclosing the address register in round parentheses.

REFERENCES

  • A. Clements;Addressing Modes, In: 68000 Family Assembly Language; pp. 99-105;PWS Publishing Company; 1994.
  • Dr. Mike Brady, Microprocessor Systems 1, dept. of Computer Science, Trinity College Dublin:
  • Stephen J Kuyath, UNCC, 2007:
  • Look on the Web at

7-1