Re: A89: recursion question
[Prev][Next][Index][Thread]
Re: A89: recursion question
TurboSoft@aol.com wrote:
> > I'm no expert, but from what I've gathered from looking at other people's
> > code, the xxx(pc) loads the effective address of xxx into the Program
> > Counter (PC). Thus, when the appropriate ROM call is called, it looks to
> > the PC for the address of xxx.
>
> okay THIS is what l was looking for, the tuitorial did not explain this.
It's a good thing that the tutorial didn't explain that, because it
isn't
correct. Accesses to xxx(PC) do not change the PC at all. Instead,
they
use the PC to find the address. Here is an example:
move.w variable(pc),d0
This copies the value of a word variable into D0. This does not modify
the
PC in any way (other than the fact that the PC is advanced to point to
the
next instruction, like always). When you use this, the assembler
calculates
the offset of the variable from the PC (that is, what the PC is when
that
instruction is run) and srotes the offset in the code. Then, the
processor
will add the offset to the PC to calculate a *temporary* address which
is
used to read the variable. Only the variables value will be loaded into
D0;
The temporary address is not stored anywhere.
Another example (probably close to what the person above was talking
about)
is PC-relative address loading, such as:
lea.l string_variable(pc),a0
In this case, the address is stored in A0. That is because the LEA
instruction stores an address into an address register, so it saves the
calculated address instead of using it. This would often be used to
load
the addresses of data structures or strings (although, the PEA
instruction
is likely to be used for stack-based parameters).
Accessing a variable PC-relative is faster than absolute addressing,
because
the processor only needs to read 1 extra word for the offset, opposed to
having to load 2 extra words to find an absolute address. In this case,
the
time the processor takes to calculate the address is not the problem for
speed.
You cannot move data to a PC-relative destination (e.g. move.w
d0,var(PC) is
not allowed). However, you can lea a PC-relative address into an
address
register and then access data relative to that register to avoid using
any
absolute references.
References: