Post Reply 
[wp34s] Is it possible to call an XROM from another one?
05-12-2015, 07:24 PM (This post was last modified: 05-13-2015 03:46 PM by emece67.)
Post: #1
[wp34s] Is it possible to call an XROM from another one?
The tittle says it all. I'm trying to insert some code as a new XROM. This code, when in a library, works OK, but when modified to be an XROM reports an "Illegal operation". The culprit seems to the be a call to W[sub-p], which is another XROM function.

Is it possible to call an XROM function from another one? If so, how?

Thanks & regards.

César - Information must flow.
Find all posts by this user
Quote this message in a reply
05-12-2015, 09:19 PM
Post: #2
RE: [wp34s] It is possible to call an XROM from another one?
(05-12-2015 07:24 PM)emece67 Wrote:  Is it possible to call an XROM function from another one? If so, how?

Not through a command that's implemented in XROM. You can, of course, XEQ code within XROM but keep in mind that there is only a single XROM environment which is separate from the standard user environment (DP, private stack and subroutine return stack).

So if you need to call a function that is implemented in XROM and is using XIN, and if your function is using XIN, too, then you need to use subroutines for the common code. Look at the statistical distributions for examples.

Marcus von Cube
Wehrheim, Germany
http://www.mvcsys.de
http://wp34s.sf.net
http://mvcsys.de/doc/basic-compare.html
Find all posts by this user
Quote this message in a reply
05-12-2015, 09:55 PM
Post: #3
RE: [wp34s] It is possible to call an XROM from another one?
Marcus got it right. The key point is xIN. These cannot ever nest. The routines in XROM that don't use xIN are all fine to nest -- there aren't many of these.

That said, there are plenty of examples of XROM subroutines that are shared. The statistical distributions are one.


- Pauli
Find all posts by this user
Quote this message in a reply
05-12-2015, 10:11 PM
Post: #4
RE: [wp34s] It is possible to call an XROM from another one?
Thanks a lot for the insight.

I was not aware of that "un-nestability" of xIN environments. Both my code and also that of W[sub-p] have xIN inside.

I'll follow your advice and try to use the W[sub-p] code in a different way.

Regards.

César - Information must flow.
Find all posts by this user
Quote this message in a reply
05-13-2015, 03:03 PM (This post was last modified: 05-13-2015 03:46 PM by emece67.)
Post: #5
RE: [wp34s] Is it possible to call an XROM from another one?
Well, now I have a working inverse Gamma in XROM (not very tidy, as I also have modified the lambert_w code to place some hooks there). But I still have some doubts about xIN/xOUT workings.

I've read that executing xIN creates a "local" 8 levels stack, a "local" return stack & changes to DP. But, does it also create a set of 16 local flags? If so, will a subsequent LocR "hide" such flags? (I think the answers are {YES, NO}, but not sure.)

Suppose also that an XROM function executes xIN, then, inside such function, there's a LocR and a GSB, and this second subroutine ends with RTN. Will such RTN "free" the LocR'ed registers? (I think {NO}, they are freed by POPLR or xOUT in the calling XROM function.)

In an XROM function calling (via GSB) other subroutines, can LocR be nested? (I have no idea.)

Thanks.

César - Information must flow.
Find all posts by this user
Quote this message in a reply
05-13-2015, 07:25 PM
Post: #6
RE: [wp34s] Is it possible to call an XROM from another one?
(05-13-2015 03:03 PM)emece67 Wrote:  I've read that executing xIN creates a "local" 8 levels stack, a "local" return stack & changes to DP. But, does it also create a set of 16 local flags? If so, will a subsequent LocR "hide" such flags? (I think the answers are {YES, NO}, but not sure.)

Not quite 16 because some of them (8 to 15) are reserved for system use. They hide the local flags in the same range. xIN does the equivalent of a call to LocR 0. If you call LocR again from the same subroutine level, that is not within code called by XEQ, the number of registers is adjusted and no new frame on top of the active one is created. If you call LocR from within a subroutine, it will get its own set of flags. But the system flags are still the same. They hide the local flags just created.

(05-13-2015 03:03 PM)emece67 Wrote:  Suppose also that an XROM function executes xIN, then, inside such function, there's a LocR and a GSB, and this second subroutine ends with RTN. Will such RTN "free" the LocR'ed registers? (I think {NO}, they are freed by POPLR or xOUT in the calling XROM function.)

RTN frees local data that has been created at the same subroutine level. Local data is allocated on the subroutine return stack. XROM code with an active xIN uses a special area in volatile memory for this purpose. So LocR inside a subroutine works in the same way as for user code but in a different memory area.

(05-13-2015 03:03 PM)emece67 Wrote:  In an XROM function calling (via GSB) other subroutines, can LocR be nested? (I have no idea.)

You should have got the idea now. Wink

Yes LocR can be nested but the reserved area is limited in size. Cf. XROM_RET_STACK_SIZE in data.h.

Marcus von Cube
Wehrheim, Germany
http://www.mvcsys.de
http://wp34s.sf.net
http://mvcsys.de/doc/basic-compare.html
Find all posts by this user
Quote this message in a reply
05-14-2015, 11:32 AM (This post was last modified: 05-14-2015 11:39 AM by emece67.)
Post: #7
RE: [wp34s] Is it possible to call an XROM from another one?
Thanks a lot Marcus. Now, knowing the internal workings, I am sure (well, almost) that my XROM code(*) will work.

Regards.

(*) if fact it is not my code, I have only adapted code from the library.

César - Information must flow.
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)