23 October 2018, 22:28 | #1 |
Registered User
Join Date: May 2017
Location: Belgium
Age: 50
Posts: 334
|
Preservation of registers
I think I read somewhere that d0 & d1 and a0 & a1 can be changed by subroutines, while the rest is supposed to be left unchanged. Is this correct? For example:
Code:
;-- copy chars into textBuffer and zero-terminate it ;in: a0: source pointer ;in: d0: # characters to copy copyToBuffer: move.l 4.w,a6 lea textBuffer,a1 jsr _LVOCopyMem(a6) ;does CopyMem() preserves a1? lea textBuffer,a1 ;if it doesn't: reset it add.l d0,a1 move.b #asciiNULL,(a1) .return: rts But you know what I mean. I'm asking because this doesn't seem to be described in the docs (http://amigadev.elowar.com/read/ADCD.../node01F9.html). So what are the default rules and assumptions for this? |
23 October 2018, 22:37 | #2 |
Registered User
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,410
|
It’s hidden away a bit, but you can read about the library function register use here: http://amigadev.elowar.com/read/ADCD.../node000F.html
The short version is that Amiga library functions use d0/d1 and a0/a1 and expect the library pointer to be in a6. All of these apart from a6 can end up trashed. Other registers are safe. Edit: made the above say what I meant Last edited by roondar; 23 October 2018 at 22:47. |
23 October 2018, 22:39 | #3 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
The usual ABI for most 68k operating systems implies that d0, d1, a0, a1 are scratch registers, which are not restored after function calls (Atari TOS also trashes d2 and a2, IIRC). This is true for all functions in AmigaOS, and for all functions generated by Amiga C compilers.
When calling your own functions in assembler you can make your own rules, but generally it is a good idea to always follow the ABI, so you can depend on it everywhere in your code and don't have to check every function you call. |
23 October 2018, 22:41 | #4 |
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
|
OS-calls treat, as you wrote, d0/d1/a0/a1 as scratch registers. You can't expect their values to be preserved, UNLESS it is specifically stated in the autodocs. (for example look at Results in this one http://amigadev.elowar.com/read/ADCD.../node0339.html)
|
23 October 2018, 22:41 | #5 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
|
23 October 2018, 22:42 | #6 | |
Registered User
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,410
|
Quote:
Edit: reading it back I do understand why you thought I meant differently. My mind was ahead of me again... |
|
23 October 2018, 22:45 | #7 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
|
23 October 2018, 22:48 | #8 |
Registered User
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,410
|
|
23 October 2018, 22:55 | #9 |
Registered User
Join Date: May 2017
Location: Belgium
Age: 50
Posts: 334
|
Thanks for clearing this up, guys!
And while on the subject of clarity: the libray docs state "Amiga library functions use registers D0, D1, A0 and A1 for work space and use register A6 to hold the library base. Do not expect these registers to be the same after calling a function." At first, I honestly also read that as "Do not expect any of the aforementioned registers..", and therefor "A6 may also be thrashed". But we've established it's only d0/d1 & a0/a1, right? Thanks for all the feedback, people, much appreciated! |
23 October 2018, 22:59 | #10 |
Registered User
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,410
|
AFAIK a6 doesn’t change.
|
23 October 2018, 23:11 | #11 |
Registered User
Join Date: May 2017
Location: Belgium
Age: 50
Posts: 334
|
That would definitely make the most sense, alright.
I'm not really sure why it is even mentioned in that part of the docs pertaining to preserved registers, to be honest. Unless the library expects you to set its own base adress there? That's not the case though, is it? I mean, I could just as well call the functions using a5 to contain the base, right? |
23 October 2018, 23:28 | #12 | |
Registered User
Join Date: Jan 2008
Location: Warsaw/Poland
Age: 55
Posts: 1,960
|
Quote:
|
|
23 October 2018, 23:36 | #13 |
Going nowhere
Join Date: Oct 2001
Location: United Kingdom
Age: 50
Posts: 8,987
|
I don't think thats entirely true.
If you open the dos.library and want to then access functions of that library, it expects you to put the dos.library base address into A6. Obviously it won't do this by itself, its something you have to specifically do, but just to point out there there are some scenarios where A6 can and has to change and you have to remember that if you then call a different library or go back to exec. |
23 October 2018, 23:39 | #14 |
Registered User
Join Date: May 2017
Location: Belgium
Age: 50
Posts: 334
|
I see, now that's interesting. Although I've always done this, I didn't know it was a requirement in some cases, so thanks for pointing that out! Can you maybe think of an example where this is the case?
|
23 October 2018, 23:42 | #15 | |
Registered User
Join Date: May 2017
Location: Belgium
Age: 50
Posts: 334
|
Quote:
1. the base needs to be in a6 2. a6 may have changed after the call That would explain the way it's frased in the docs, though. |
|
24 October 2018, 00:00 | #16 | |
Registered User
Join Date: Jan 2008
Location: Warsaw/Poland
Age: 55
Posts: 1,960
|
Quote:
move.l A6,A5 jsr -$xx(a5) but no big sense for me. |
|
24 October 2018, 00:03 | #17 | |
Registered User
Join Date: Jan 2008
Location: Warsaw/Poland
Age: 55
Posts: 1,960
|
Quote:
|
|
24 October 2018, 00:11 | #18 | |
Registered User
Join Date: May 2017
Location: Belgium
Age: 50
Posts: 334
|
Quote:
Last edited by guy lateur; 24 October 2018 at 00:14. Reason: Added lame bases joke |
|
24 October 2018, 00:22 | #19 | |
Registered User
Join Date: Apr 2005
Location: digital hell, Germany, after 1984, but worse
Posts: 3,366
|
Quote:
|
|
24 October 2018, 00:26 | #20 | |
Registered User
Join Date: Jan 2008
Location: Warsaw/Poland
Age: 55
Posts: 1,960
|
Quote:
http://wt.exotica.org.uk/test.html |
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
OCS collision and clx registers | PiCiJi | Coders. Asm / Hardware | 11 | 30 July 2019 06:15 |
A4000 IDE registers | mark_k | Coders. Asm / Hardware | 6 | 11 May 2015 17:05 |
Using FPU registers? | oRBIT | Coders. General | 16 | 26 April 2010 13:34 |
Need DA8000-DAFFFF registers documentation | BlueAchenar | Coders. General | 2 | 13 December 2008 15:39 |
Gayle Hardware Registers | bluea | support.Hardware | 5 | 09 July 2006 17:07 |
|
|