Thanks for the information.  

I understand this now. From your answer, it seems that at run time 'func' will
have the absolute address value of function "MyFunc" when "func = MyFunc" is
execuated.  

I looked at the disassembled code0001 resource, then that part come to this:

0000678a   4e560000     L858            LINK    A6,#0
0000678e   2f0a                         MOVE.L  A2,-(A7)
00006790   42a7                         CLR.L   -(A7)
......
000067bc   4e75                         RTS
......

00006918   41fafe70                     LEA L858,A0
0000691c   2808                         MOVE.L  A0,D4
......

where L858 is the lable for "MyFunc". I guess L858 is the relative address from
the head of the segment. So I am expecting the value stored in memory location
specified by D4 is actually PC+L858, is it right?

When the MyFunc is called via func, the code is like this:

000069da   2044                         MOVEA.L D4,A0
000069dc   4e90                         JSR (A0)
......
A0 should have the absolute address for JSR, right?

If that is the case, how would I declare a variable to store the relative
offset of the function "MyFunc"?

"int (*func)();" will get the absolute address value.  Would it be different if
I have "void *funcP;" and use "funcP = MyFunc;"?

Thanks.

Max
--- Ben Combee <[EMAIL PROTECTED]> wrote:
> "Max Bian" <[EMAIL PROTECTED]> wrote in message
> news:71546@palm-dev-forum...

> >
> > int (*func)();
> >
> > and later I will assign a function address to it by:
> >
> > func = MyFunc;
> >   where "MyFunc" is something like this:
> >
> > int MyFunc(...){...};
> >
> > My question is, is the value (address?) of MyFunc determined as
> compile time?
> > If so, how do I obtain that value after compilation?  I had some
> experience
> > with x86 assembly but I am not familiar with m68k.
> 
> If MyFunc is in the same segment, the address is computed by adding a
> constant offset value from the current PC (program counter) when the
> "func = MyFunc" instruction is executed.
> 
> If MyFunc is in a different segment, the address is retrieved from the
> global jumptable, again using a constant offset, but now from the global
> register (usually A5).  The jumptable is structured as a series of JMP
> instructions, but the opcode can be skipped to get the actual address.
> 
> You can get a relative value after compilation by looking at the linker
> map file, but that will only tell you how far into a segment the
> function is.  You can't determine the true location until runtime,
> because when your application isn't running, its segments are unlocked
> and may move around memory.
> 


__________________________________________________
Do You Yahoo!?
Check out Yahoo! Shopping and Yahoo! Auctions for all of
your unique holiday gifts! Buy at http://shopping.yahoo.com
or bid at http://auctions.yahoo.com

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to