EASy68K  
It is currently Thu Apr 02, 2020 12:44 pm

All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Thu Nov 28, 2013 4:06 pm 
Offline

Joined: Wed Nov 27, 2013 12:06 am
Posts: 3
How do I pass an adress by stack and pop it and use as address in a routine? my following routine crash EASy68K (or goes in a infinity loop?)

Code:
START ORG $1000
        MOVE.L T,D0
        MOVE.L D0,-(SP)
        BSR PRINTS
        ADDQ.L #4,SP
        MOVE #9,D0       
        TRAP #15

PRINTS:       
        MOVE 4(SP),A1
        MOVE #14,D0
        TRAP #15
        RTS


I tried with the PEA instruction too. But it doesn't worked:

Code:
  PEA T(PC)
  BSR PRINTS
  *....


Thanks in advance.


Top
 Profile  
 
PostPosted: Thu Nov 28, 2013 10:00 pm 
Offline
User avatar

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1118
The first MOVE in PRINTS must be .L.
Code:
PRINTS:       
        MOVE.L 4(SP),A1

_________________
Prof. Kelly


Top
 Profile  
 
PostPosted: Wed Dec 25, 2013 1:33 pm 
Offline

Joined: Tue Nov 15, 2005 7:58 am
Posts: 129
Location: Oregon, USA
Code:
PRINTS:       
        MOVE.L 4(SP),A1


or
Code:
PRINTS:       
        MOVEA 4(SP),A1

perhaps?

[wish] Or LINK? I could use more examples of how LINK is supposed to be used with OFFSET. One of the examples we have (between Tutorial4 and the LINK enter in the help file) does references to stacked parameters to the subroutine, and the other to local variables created on the stack. I think. :( In any case, the way they use OFFSET seems inconsistent between them. A(nother) well-commented example that does both would be helpful. (I've seen http://www.easy68k.com/EASy68Kforum/viewtopic.php?f=4&t=372) [/wish]

Just a quibble, but you wouldn't actually POP a passed parameter from the stack, as it'd mess up the return address -- unless I'm misunderstanding. :-? You'd access it in place, then drop it after returning (or in special cases, while returning?)
Example from Tutoral4:
Code:
    lea     (8,SP),SP   clean up the stack

which removes (drops) the two .L parameters pushed before the BSR.


Top
 Profile  
 
PostPosted: Thu Jan 09, 2014 9:22 pm 
Offline

Joined: Mon Jul 26, 2010 11:43 pm
Posts: 198
Location: Aurora, IL
gtippery wrote:
Or LINK? I could use more examples of how LINK is supposed to be used with OFFSET. One of the examples we have (between Tutorial4 and the LINK enter in the help file) does references to stacked parameters to the subroutine, and the other to local variables created on the stack. I think. :( In any case, the way they use OFFSET seems inconsistent between them. A(nother) well-commented example that does both would be helpful. (I've seen http://www.easy68k.com/EASy68Kforum/viewtopic.php?f=4&t=372)


I think tutorial4 is a bit deceptive, there are 3 parameter in the positive portion of the stack, one being the result.

http://www.easy68k.com/examples/tutorial4.zip
* The OFFSET directive is used to access the parameters by name.
* 4 bytes for A0 saved by link, 4 bytes for saving D0

This is however NOT the case, its the PC and A0 which are on the stack which are being accounted for.

The 2*4 comment refers to A0 and D0, but D0 is being pushed AFTER the LINK has done the PUSH A0, and assignment of A0 to the SP.

STACK AFTER:
link A0,#0 create stack frame
move.l D0,-(SP) save D0

NUM1 [A0+16]
NUM2 [A0+12]
SUM [A0+8]
PC [A0+4] <- BSR puts this here
A0 (OLD) [A0+0] <- LINK puts this here
D0 [A0-4] <- PUSH puts this here


Top
 Profile  
 
PostPosted: Sat Jan 11, 2014 7:26 pm 
Offline
User avatar

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1118
The comments in tutorial4 are correct as shown.
Code:
*------------------------------------
* Add two numbers passed as parameters on the stack.
* The sum is returned on the stack.
* The OFFSET directive is used to access the parameters by name.
* 4 bytes for A0 saved by link, 4 bytes for return address
        offset  4+4
sum     ds.l    1
num2    ds.l    1
num1    ds.l    1
        org     *           end the offset

Adder2
    link    A0,#0           create stack frame
    move.l  D0,-(SP)        save D0
    move.l  (num1,A0),D0    access num1 parameter
    add.l   (num2,A0),D0    add num2 parameter
    move.l  D0,(sum,A0)     store result in sum parameter
    move.l  (SP)+,D0        restore D0
    unlk    A0
    rts                     return

Clive, you must have an older version of tutorial4.

_________________
Prof. Kelly


Top
 Profile  
 
PostPosted: Mon Jan 13, 2014 3:41 pm 
Offline

Joined: Mon Jul 26, 2010 11:43 pm
Posts: 198
Location: Aurora, IL
I pulled the .ZIP file cited, checking the download date on my system 01-09-14, containing tutorial4.x68 from 11-11-12

Same one still there today.

http://www.easy68k.com/examples/tutorial4.zip
On
http://www.easy68k.com/easy68kexamples.htm

Code:
*------------------------------------
* Add two numbers passed as parameters on the stack.
* The sum is returned on the stack.
* The OFFSET directive is used to access the parameters by name.
* 4 bytes for A0 saved by link, 4 bytes for saving D0
        offset  2*4
sum     ds.l    1
num2    ds.l    1
num1    ds.l    1
        org     *           end the offset

Adder2
    link    A0,#0           create stack frame
    move.l  D0,-(SP)        save D0
    move.l  (num1,A0),D0    access num1 parameter
    add.l   (num2,A0),D0    add num2 parameter
    move.l  D0,(sum,A0)     store result in sum parameter
    move.l  (SP)+,D0        restore D0
    unlk    A0
    rts                     return


Top
 Profile  
 
PostPosted: Wed Jan 15, 2014 1:23 pm 
Offline
User avatar

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1118
Ah, I forgot that Tutorial 4 was still on the website. It is included in the EASy68K download in the Examples folder.

_________________
Prof. Kelly


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 guests


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