English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Asm / Hardware

 
 
Thread Tools
Old 06 January 2022, 18:40   #1
DanielAllsopp
Registered User
 
DanielAllsopp's Avatar
 
Join Date: Feb 2018
Location: Northumberland, UK
Posts: 272
Different results with BSR and non-BSR code

Evening!

Why would calling code via a BSR act differently to calling the exact same code inline?

For example, in my startup I've got the following to disable the OS:

Code:
  lea $dff000,a6
  bsr WaitEOF
  move.l $1c(a6),-(sp)
  move.w 2(a6),-(sp)
  move.l INTVECTORL2(a4),-(sp)
  move.l INTVECTORL3(a4),-(sp)
Now, if I call that code directly within my Start: routine then it works fine, however, if I move it into its own subroutine, i.e.

Code:
DisableSystem:
  lea $dff000,a6
  bsr WaitEOF
  move.l $1c(a6),-(sp)
  move.w 2(a6),-(sp)
  move.l INTVECTORL2(a4),-(sp)
  move.l INTVECTORL3(a4),-(sp)
rts
and then call 'bsr DisableSystem' in its place, it hangs on the following line:

Code:
  move.l $1c(a6),-(sp)
So I'm thinking it's got something to do with the stack pointer? I've been banging my head against the wall for a good while now over the last two days and I've ran out of ideas.

Anyone else know why this would be the case?
DanielAllsopp is offline  
Old 06 January 2022, 18:43   #2
StingRay
move.l #$c0ff33,throat
 
StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
Just a hint: watch your stack. And ask yourself where the return address comes from. And then check your "DisableSystem" routine.
StingRay is offline  
Old 06 January 2022, 18:46   #3
paraj
Registered User
 
paraj's Avatar
 
Join Date: Feb 2017
Location: Denmark
Posts: 1,098
BSR/RTS also uses the stack, so when you do:
Quote:
move.l INTVECTORL3(a4),-(sp)
rts
you'll "return" to whatever is stored at INTVECTORL3(a4).
paraj is offline  
Old 06 January 2022, 19:15   #4
DanielAllsopp
Registered User
 
DanielAllsopp's Avatar
 
Join Date: Feb 2018
Location: Northumberland, UK
Posts: 272
Ooooooooh... of course, the return address is stored in the stack isn't it!
DanielAllsopp is offline  
Old 06 January 2022, 21:46   #5
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 3,215
Quote:
Originally Posted by DanielAllsopp View Post
Anyone else know why this would be the case?

The "why" has been answered, though there is also a solution for you in case you want to use a subroutine for storing data on the stack.
Code:
Sub:
  ... do something ...
 move.l (a7)+,d0    ;get return address
 move.l ....,-(a7)    ;store stuff on the stack
 move.l ...,-(a7)    ; more stuff...
 move.l d0,-(a7)   ; restore return address
 rts
All this beside, I believe instead of disabling the system it would be a much better approach to use the system.
Thomas Richter is offline  
Old 06 January 2022, 23:35   #6
DanielAllsopp
Registered User
 
DanielAllsopp's Avatar
 
Join Date: Feb 2018
Location: Northumberland, UK
Posts: 272
Quote:
Originally Posted by Thomas Richter View Post
The "why" has been answered, though there is also a solution for you in case you want to use a subroutine for storing data on the stack.
Code:
Sub:
  ... do something ...
 move.l (a7)+,d0    ;get return address
 move.l ....,-(a7)    ;store stuff on the stack
 move.l ...,-(a7)    ; more stuff...
 move.l d0,-(a7)   ; restore return address
 rts
All this beside, I believe instead of disabling the system it would be a much better approach to use the system.
Thanks for that Thomas, much appreciated.

Regarding the system though; the whole point of me jumping into ASM coding on the Amiga in the first place was to learn how to 'bang the metal' as was done in the good old days. I've coded plenty of system friendly Amiga apps in the past so time to go old skool I reckon!
DanielAllsopp 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
Profiling C code, interpreting results Ernst Blofeld Coders. C/C++ 5 19 November 2020 18:45
bsr.l on 68000 doesn't crash StingRay support.WinUAE 5 22 September 2012 21:43
Undefined symbol bsr.b init_bitmaps VoltureX Coders. General 12 13 November 2011 16:11
clr.b -(SP) followed by bsr... Photon Coders. General 19 18 January 2011 22:42
68040 MMU jsr/bsr Toni Wilen Coders. General 5 28 April 2010 20:57

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 18:57.

Top

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