Welcome, Guest. Please login or register.

Author Topic: Couple asm questions (Subr parameter passing, return codes and errors, and register preservation)  (Read 1015 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
1. The reason is that the code is easier to maintain when there is consistency in argument passing. Also, C typically uses d0-> for numeric arguments, and a0-> for pointers, and the same is "natural" for asm too.

Also d0/d1/a0/a1 are scratch registers, so they're "free" when passing arguments (that is: not used by the main app as these registers are trashed by the OScall / subroutine anyway).

2. CLI programs must return the ReturnCode in d0. The result is the success/warn/failure status of the program. 0 means success (RETURN_OK), 5 means warning (RETURN_WARN), 10 means error (RETURN_ERROR), 20 means failure (RETURN_FAIL). dos/dos.i defines these. Workbench ignores the value returned in d0.

3. Register preservation is not needed, except in your own subroutines (so that you don't trash the registers of the main program). How and which registers you save is upto you. OS calls trash d0/d1/a0/a1, unless if otherwise stated in the function AutoDoc.

At program exit a7 (sp) must be the same value as when the program was entered. For CLI programs d0 must be the ReturnCode as explained above.

Quote
Doesn't the OS take care of this automatically when switching between tasks?

Yes it does. Task switching saves all register automagically. What you need to do is to save registers in your own subroutines so you don't trash registers of the main app.
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Quote
AmigaOS up to ROM 2.04. Is the automatic register preservation a feature of AmigaOS > 2.04?

Task switching has always and always will preserve all registers. All AmigaOS versions.

The need not to preserve any registers at program exit (except a7) is separate from the above. It has always been like this in AmigaOS and will continue to be like that.