IntroMC68000
Together with the memory space and any separate I/O space, the registers comprise what is known as the programming model for the processor.
The manner in which the target address or effective address is identified within the instruction is called the addressing mode.
Stack Applications.
A subroutine which is structured to call itself is said to be recursive. Recursive programs are seldom written because they are often confusing and difficult to understatnd.
Dynamic allocation of memory has another important application. It permits a routine to be interupted by an input/output device and then to be called while that device is being serviced. In this situation, the routine is temporarily suspended in the middle of its execution and then restarted at the beginning and tun to completion before continuing on with its suspended execution. This routine is said to be reentrant.
MC68000 has A7 for user-stack-pointer and A7' for system-stack-pointer.
Passing parameters to subroutine.
One way is to pick up or create the parameters in processor registers and allow them to remain there while calling the subroutine.
Another way to pass parameters is to push them onto the stack prior to calling the subroutine. When this approach is used with the system stack, the return address will be pushed on top of the parameters during the call. This requires that the subroutine reach down into the stack to access the parmeters.
Another to pass parameters to a subroutine is to pass a starting address of a list of parameters stored in memory. The starting address may be passed in any address register, or it may be pushed onto the system stack just prior to calling the subroutine. If n bytes of parameters were pushed onto system stack, the offset of n bytes is required to reach below the return address. Later on during the subroutine the stack should be cleaned up by moving the return address n locations in memory and incrementing SP by n. May be done by MOVE.L (SP)+, (SP), since the post-increment takes place after the read but before the write. Alternatively, the calling program could clean up the stack by incrementing SP by n with an instruction such as LEA 4(SP), SP immediately after the instruction which calls the subroutine.
LINK and UNLK is used by subroutine to allocate memory space dynamically on the system stack to be used for temporary storage during that specific call.