English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. Blitz Basic

 
 
Thread Tools
Old 26 January 2017, 15:14   #1
idrougge
Registered User
 
Join Date: Sep 2007
Location: Stockholm
Posts: 4,332
Call vs JSR

Quote:
Originally Posted by The manual
Call Address
Call make program flow to be transferred to the memory location specified by Address.
NOTE that Call is for advanced programmers only, as incorrect use of Call can lead to severe problems - GURUS etc!
A 68000 JSR instruction is used to transfer program flow, so an RTS may be used to transfer back to the Blitz program.
Is there any actual difference between the Call command and just an inline JSR?
idrougge is offline  
Old 26 January 2017, 15:57   #2
Daedalus
Registered User
 
Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,334
Hmmm, it doesn't sound like it. I've only ever used JSR so I can't be sure, but it just sounds like a "BASIC-ified" wrapper for JSR.
Daedalus is offline  
Old 26 January 2017, 17:08   #3
Daedalus
Registered User
 
Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,334
I can't make sense of the token numbers in the Blitz source, so I'll have a look tonight when I'm in front of my Amiga. But it looks like it just does some stack shuffling and then calls the JSR:

Code:
JL_0_25C:
CNIF #return0=1
  ADDQ.l #4,a7
  JSR -$8a(a6)
  MOVEM.l (A7)+,A0-A1/A6
  RTS
CELSE
  MOVE.l #AL_0_268,D0
 TRAP #$0
CEND
But as I say, I don't know whether that's the correct token or not...
Daedalus is offline  
Old 27 January 2017, 03:32   #4
Anakirob
Unregistered User
 
Anakirob's Avatar
 
Join Date: Nov 2005
Location: Tasmania
Age: 42
Posts: 893
I can't say what the differences are between many Blitz functions and their 68K ASM equivalents.

Personally I made a habit of using 68K instructions instead of Blitz functions whenever I could, under the assumption that using them might somehow make my code that little bit more efficient, for example I would use:

JSR instead of GoSub or GoTo
RTS instead of Return
LSL instead of *2, *4, *8, etc.
LSR instead of /2, /4, /8, etc.
and sometimes BEQ or BNE with the appropriate value instead of JoyB and other condition checks.

But I honestly don't know if there is any actual improvement/optimisation of final binary going on when using these instead of Blitz functions (although I suspect that LSL/LSR are quite a bit faster than standard math routines). If someone could shed some light on the issue that would be handy.

Last edited by Anakirob; 27 January 2017 at 03:39. Reason: typo
Anakirob is offline  
Old 27 January 2017, 11:03   #5
idrougge
Registered User
 
Join Date: Sep 2007
Location: Stockholm
Posts: 4,332
Even the AMOS compiler translates multiplications in powers of two into shifts. I can't imagine Blitz being any worse.
idrougge is offline  
Old 31 January 2017, 17:46   #6
idrougge
Registered User
 
Join Date: Sep 2007
Location: Stockholm
Posts: 4,332
So does this mean that A0, A1 and A6 are saved on the stack using CALL?
idrougge is offline  
Old 31 January 2017, 19:49   #7
Lonewolf10
AMOS Extensions Developer
 
Lonewolf10's Avatar
 
Join Date: Jun 2007
Location: near Cambridge, UK
Age: 44
Posts: 1,924
Why not try a simple test to find out?
Lonewolf10 is offline  
Old 31 January 2017, 23:08   #8
idrougge
Registered User
 
Join Date: Sep 2007
Location: Stockholm
Posts: 4,332
I don't have the necessary mastery of the debugger.
idrougge is offline  
Old 02 February 2017, 12:50   #9
Daedalus
Registered User
 
Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,334
Well, bear in mind that I'm still not sure that's the actual Call token code... But it actually looks like it's pulling those registers back off the stack after returning from the JSR. Not sure at which point they're pushed onto the stack, so I think there's more to it. Thinking about it, if Call just jumps the PC to another address, why would it need any stack shuffling at all?
Daedalus is offline  
Old 02 February 2017, 12:59   #10
idrougge
Registered User
 
Join Date: Sep 2007
Location: Stockholm
Posts: 4,332
It would make more sense if it actually saved those registers which are vital to Blitz instead of some random address registers.
idrougge is offline  
Old 02 February 2017, 15:38   #11
Daedalus
Registered User
 
Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,334
Yep, which is why I have my doubts about it now. Hmmmm, more investigation is needed...
Daedalus is offline  
Old 02 February 2017, 22:45   #12
Lonewolf10
AMOS Extensions Developer
 
Lonewolf10's Avatar
 
Join Date: Jun 2007
Location: near Cambridge, UK
Age: 44
Posts: 1,924
In standard ASM, a6 is used for the user/custom stack pointer and a7 (or PC) is used as the program counter.

Of course, this is Blitz and may not be following normal ASM conventions...
Lonewolf10 is offline  
Old 02 February 2017, 22:50   #13
Daedalus
Registered User
 
Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,334
Yeah, Blitz uses A7 as the stack pointer according to the documents. PC is its own separate register, A6 can be used for whatever you want it seems.
Daedalus is offline  
Old 03 February 2017, 01:27   #14
idrougge
Registered User
 
Join Date: Sep 2007
Location: Stockholm
Posts: 4,332
Quote:
Originally Posted by Lonewolf10 View Post
In standard ASM, a6 is used for the user/custom stack pointer and a7 (or PC) is used as the program counter.

Of course, this is Blitz and may not be following normal ASM conventions...
A7 is stack pointer and PC is PC, you mean.
idrougge is offline  
Old 04 February 2017, 21:48   #15
BippyM
Global Moderator
 
BippyM's Avatar
 
Join Date: Nov 2001
Location: Derby, UK
Age: 48
Posts: 9,355
I thought this too!

Quote:
Originally Posted by idrougge View Post
A7 is stack pointer and PC is PC, you mean.
BippyM is offline  
Old 05 February 2017, 01:03   #16
Lonewolf10
AMOS Extensions Developer
 
Lonewolf10's Avatar
 
Join Date: Jun 2007
Location: near Cambridge, UK
Age: 44
Posts: 1,924
Quote:
Originally Posted by idrougge View Post
A7 is stack pointer and PC is PC, you mean.
No.

It's been over a year since I coded in ASM so when you questioned what I wrote I wondered if I was getting things mixed up.
Here is a quote from a Wiki page (https://en.wikibooks.org/wiki/68000_Assembly):

Quote:
There are seven address registers: a0, a1, a2, a3, a4, a5, and a6. These are typically used as pointers.

There is one active stack pointer: SP, also called a7. Normally the processor is in user mode. In user mode, SP refers to the User Stack Pointer (USP) register. (During interrupts, the active stack pointer SP is another register called the Interrupt Stack Pointer or the System Stack Pointer. The 68020 and higher processors have a third register called the Master Stack Pointer. Neither the ISP nor the MSP can be accessed in user mode).
Register a7 is a special register and I usually don't touch it when coding in ASM.

I note that I quoted a Wiki and it may be wrong, but I am pretty sure that the above information is correct.

Edit: After re-reading what I originally wrote and what I just posted, I realise I meant SP instead of PC

Last edited by Lonewolf10; 05 February 2017 at 01:10. Reason: Realised my confusion between PC and SP
Lonewolf10 is offline  
Old 05 February 2017, 03:00   #17
idrougge
Registered User
 
Join Date: Sep 2007
Location: Stockholm
Posts: 4,332
A6 is usually used for library bases as far as I know.
idrougge is offline  
Old 05 February 2017, 22:40   #18
Lonewolf10
AMOS Extensions Developer
 
Lonewolf10's Avatar
 
Join Date: Jun 2007
Location: near Cambridge, UK
Age: 44
Posts: 1,924
Quote:
Originally Posted by idrougge View Post
A6 is usually used for library bases as far as I know.
Yes, that is what the official documentation recommends. However, it is up to the programmer if they wish to follow it and if they decide to take full control of the machine (e.g. for demo's or games) and pause the background processes (e.g. workbench) then a6 can be used for anything.
Lonewolf10 is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Call for testing cla Coders. System 0 26 October 2016 20:49
Let's call it karma. Or something. trooper Retrogaming General Discussion 10 19 September 2013 23:44
Game appears to use weird JSR instructions MethodGit Coders. General 15 18 March 2011 16:26
68040 MMU jsr/bsr Toni Wilen Coders. General 5 28 April 2010 20:57
Call to all UK Sceners, old and new! rc55 Amiga scene 6 12 February 2008 01:41

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 17:50.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.09295 seconds with 15 queries