Re: A89: recursion question


[Prev][Next][Index][Thread]

Re: A89: recursion question




Justin M Bosch wrote:

> > move.l stuff(pc),d5   ;Same as above, but PC-relative (faster,
> >smaller)
> 
> Everything makes sense to me except this.  How does the PC come into play
> here, and if this one is faster and smaller, why would anyone use "move.l
>  stuff, d5"?

The PC-relative addressing mode uses addresses realtive to the PC
instead
of absolute addresses.  If you use "move.l stuff, d5" it would store the
address of stuff in the code.  However, if you wrote "move.l stuff(pc),
d5"
it would just keep a 16-bit offset from the PC in the code.  This also
avoids the need for a relocation entry.  If the value is in the code,
there
is absolutely no reason not to use PC-relative addressing to read it.
However, you can not have a PC-relative *destination*.  

Furthermore, PC-relative addressing will only work if the value is in
the
code.  You can't use it to access LCD_MEM or something like that which
is
at an absolute address outside the program, and you can't use it for BSS
sections.  In that cases, it's a good idea to load a pointer to the BSS
section into an address register, and use address register addressing
with
displacement (e.g. 16(a0)) to access everything there, which is just as
fast.

On the 68000, relative is faster and smaller!  On the Z-80, IX-relative
addressing is slower and takes more space, but on the 68000 you should
use
relative addressing whenever possible.


Follow-Ups: References: