[A89] Re: functions addresses


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

[A89] Re: functions addresses




<< Also, in the TIGCC docs, for ROM calls, it will say a number. Multiply
that number by 4 and add it to 0xc8, and you will get its address in the
jump table. >>

Close, but not quite.  You need to multiply the number by 4 and add it to
_the address pointed to at the address 0xC8_.  In other words, there's
another level of indirection.  And this extra indirection is what your code
does:

> move.l $c8,a5

This doesn't load the actual number 0xC8 (that would be 200 in decimal) into
a5.  It looks at the memory address 0xC8, takes the data located at that
address, and puts that data in a5.

To make a5 literally hold the value 0xC8, you'd need to use:

    move.l #$c8,a5

But then what you really need is the value contained at that address, so
you'd follow that with:

    move.l (a5),a5

Of course, the first move.l that you provided does both of these in one
step, so it's much nicer.

> move.l ScreenClear*4(a5),a0

And for AMS novices, let me explain this code.  It uses "X(an)" addressing
mode, where X is a constant value.  What this does is calculate the sum of
an and X, or (an+X).  So what this line does is take a5, adds
(ScreenClear*4), and puts that address in a0.  The address in a0 happens to
hold the address of the ScreenClear function.

> jsr (a0)

And this jumps to the address that a0 contains, which is the ScreenClear
function.

Some of this indirection and dereferencing takes a while to figure out.  If
you already know C or another ASM language, it'll be a bit easier.

    -Scott