# LINK Instruction

The instruction LINK creates a stack frame, a temporarily allocated piece of memory on the stack. The instruction is often used in high-level languages when allocating memory for local variables in procedures. When the procedure is deactivated, the variables disappear which saves memory. LINK has two operands. The first is an address register and the second is a twos complement value, which is the size of the frame (often negative since the stack grows backwards). When the instruction is executed, the address register is pushed onto the stack and the newly updated A7 is copied to the address register. The immediate value is added to the Stack register (A7).
The local memory is accessed by negative shifting the address register. That way you can use local variables without worrying about other data that is pushed or popped from the stack. This is provided you keep in the range you specified when you called the LINK opcode. The instruction UNLK removes the stack frame and restores the stack pointer.
ADDRESS METHODS: None
DATA LENGTH: N/A
FLAGS: Unaffected
SYNTAX: LINK An,#<shifting>
Note that the use of LINK allows Reentrant programs.