views:

65

answers:

1

hi,

While going through some data sheets of a processor architecture , i saw the terms, short addressing mode and long addressing mode

Can anybody give me the general idea of the terms(not needed to be processor specific!)

/renjith_g

+2  A: 
  • A short addressing mode uses a relative address, calculated as (some register + some smallish constant), which generally allows small/few/fast instructions, but can only address a small range of memory;
  • A long addressing mode uses absolute addresses, which generally require large/many/slow instructions, but which can access any memory.

I'll give as an example ARM code, but this probably applies (in the general sense) to many other processors.

Each ARM instruction (ignoring Thumb) is 32 bits long, and for the sake of this example, we'll pretend the ARM can access a 32-bit address space.

Each instruction must be decoded, essentially by breaking down those 32 bits into various fields - and some of those bits must be used to store the type of the instruction.

Hopefully therefore, it should be clear that you can't load an arbitrary address into a register in one instruction:

MOV Rn, #AABBCCDD

Won't work - since we need to use bits to specify the instruction (MOV) and the destination register (Rn), we don't have 32 bits left to store a 32-bit address.

So, if we want the address of something in a register, we have a few options:

1. Use PC-relative

There's a pseudo-op which works as follows:

ADR Rn, .label
...
.label

Which gets expanded to:

ADD Rn, PC, (.label - here)

Provided .label is within about 4k of the current instruction, we can add/subtract from the current PC (program counter) to get that address. That's a relative address.

2. Use multiple instructions

You can build up an arbitray address using adds or ors:

MOV Rn, #AA000000
ADD Rn, Rn, #00BB0000
ADD Rn, Rn, #0000CC00
ADD Rn, Rn, #000000DD

(Actually you can do it much more efficiently, but you get the idea).

3. Store the absolute address in a known relative location

If you know the address you want is stored nearby, you can load it from memory:

ADR Rn, .store
LDR Rn, [Rn]

.store
EQU #AABBCCDD

Now, other processor architectures may have variable-length instructions (eg x86), so you can choose whether to use a short relative addressing mode (eg relative to PC or another register), or a longer (and probably) slower instruction which holds an entire 32-bit address.

stusmith
I have got some idea.But can you be little bit specific towards the above two addressing modes?/renjith_g
Renjith G

related questions