EASy68K  
It is currently Wed Nov 22, 2017 2:38 pm

All times are UTC




Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Stack Frames in EASy68K
PostPosted: Tue Mar 27, 2007 1:25 am 
Offline
User avatar

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1049
Stack frames are commonly used in subroutines to create local variables on the stack. Accessing the variables can be a little tedious. Here is a solution that might make things just a little easier.

Code:
        ORG   $1000
START:                   ; first instruction of program
        BSR   FRAMEIT

        MOVE.B  #9,D0
        TRAP    #15      ; halt simulator


*---------- FRAMEIT subroutine ----------
SIZE    EQU -3*4         3 long words, negative for stack frame
        OFFSET  SIZE     offset to local variables is determined
num1    DS.L    1
num2    DS.L    1
num3    DS.L    1
        ORG   *
   
FRAMEIT LINK    A0,#SIZE              create stack frame
        MOVEM.L A0-A1,-(A7)           put some more stuff on the stack just for fun
        MOVE.L  #$11111111,(num1,A0)  access the local variable using a label
        MOVE.L  #$22222222,(num2,A0) 
        MOVE.L  #$33333333,(num3,A0)
        MOVEM.L   (A7)+,A0-A1         get stuff off stack
        UNLK    A0                    remove stack frame
        RTS

        END   START      ; last line of source


_________________
Prof. Kelly


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group