Dead Hackers Society
Other BBSes »
 
 
Demoscene  Coding  CT60  Buy/sell

Atari coding BBS
 
Re: LINK + UNLK instructions
Posted by: ray Mar,01.2009-23:54 

hi there sunny,

make sure you understand what the link instruction does and what it's actually meant for... i.e. reserve a local stack-frame e.g. for a subroutine, or small chunks of dynamically allocated memory.
link will
1. stack the specified address-register
2. save the current stackpointer to the specified address-reg.
3. increment the stackpointer by the given displacement

since the stack grows into the lower address-range, it only makes sense to use link with negative displacement, allowing to put your new stack "on-top" (below, in terms of addresses) of your local-frame, now accessed by the address-reg. specified along with the link-instruction. also keep in mind your local stackpointer will point to the bottom (top in terms of addresses) of the allocated frame.
giving a positive displacement, would lead to your frame being overwritten by new return-addresses/whatsoever stacked by possibly executed iterrupt-service-routines since the "linking" an so on.

using a simple "lea.l 4(sp),a6" would be of more use for the situation posted above. since your point is skipping the stacked return-address in order to directly access the stacked parametes (which is fine and which is the prevalent method) rather then actually needing to allocate a stackframe, which would make sense in case you run out of registers in your subroutine, for example.

best regards,
ray//.tSCc.







[All messages in this thread]    [Start new thread]

Topic Posted by  Date 
LINK + UNLK instructions Simon Sunnyboy / Paradize Mar,01.2009-14:02
  Re: LINK + UNLK instructions ray Mar,01.2009-23:54
    Re: LINK + UNLK instructions Simon Sunnyboy / Paradize Mar,02.2009-00:34


Reply to this message
Name:
Topic:
Anti-troll code:

Message:

What's the anti-troll code?
That's your personal code to be able to add comments and messages on the dhs.nu site.
Don't have a code or forgot it? Fix it here.
© 1994-2024 Dead Hackers Society Contact: Anders Eriksson