/* PDL ********************************************* BEGIN Stack PUT started message PUSH 2 args onto stack CALL test function RESTORE stack PUT finished message END ***************************************************/ /* Registers used ********************************** a0, a1, d0 ***************************************************/ .NOLIST .INCLUDE "..\\Include\\ASCII.i" .LIST .TEXT 1 StartMsg: .ASCII "Stack test start" .BYTE CR, LF, 0 MidMsg: .ASCIZ "D0 arg is " FinishMsg: .ASCII "Stack test end" .BYTE CR, LF, 0 .TEXT 0 .GLOBAL Stack Stack: lea StartMsg, a0 | show starting jsr PrintMsg pea MidMsg | set msg as arg move.w #0x1234, d0 | set word move.w d0,-(sp) | as another jsr TestStack add.l #6, sp | correct stack lea FinishMsg, a0 | show done jsr PrintMsg rts | exit /* PDL ********************************************* BEGIN TestStack SAVE registers SET stack frame COPY args to locals PUT string from arg PUT word from arg FREE stack frame RESTORE regs END ***************************************************/ /* Registers not saved ***************************** a0, d0 ***************************************************/ TestStack: movem.l a1-a2/d1-d2,-(sp) | save regs link a6,#-6 | set stack frame /* Stack Frame details: a6 + 26 a0.l content from pea a6 + 24 d0.w content from move a6 + 20 return address.l from jsr a6 + 16 movem.l d2 a6 + 12 movem.l d1 a6 + 8 movem.l a2 a6 + 4 movem.l a1 a6 + 0 longword for a6 a6 - 2 word for d0 a6 - 6 longword for a0 .EQU ARG_A0,26 | 2 args .EQU ARG_D0,24 .EQU VAR_A0,-6 | 2 locals .EQU VAR_D0,-2 move.l (ARG_A0, a6), a0 | get longword arg move.l a0, (VAR_A0, a6) | store as local move.w (ARG_D0, a6), d0 | get word arg move.w d0, (VAR_D0, a6) | store as local jsr PrintMsg | print string from arg move.b #4, d1 jsr OutHex | print word from arg jsr NewLine | be tidy unlk a6 | stack frame done movem.l (sp)+, a1-a2/d1-d2 | restore regs rts | return