home .. forth .. misc mail list archive ..

No Subject


Dave Lowry:

>  VARIABLE IPSAVE
>  VARIABLE IPNEW
>  HERE 6 + IPNEW !
>
>  ' TX!
>
>  ASSEMBLER
>
>  CODE CALL-TX!
>    / some code...
>    A PUSH IPSAVE # NOP
>    A! POP !A IPNEW #
>    A! # PUSH ;'
>    IPSAVE # NOP A! @A
>    A! NOP NOP NOP
>    / some more code...
>    NEXT
>    END-CODE

Raul:

>(1) what is IPNEW for?  Why don't you do anything with it after
>returning?

IPNEW holds the address that I want Jeff's P21Forth word to return to.
In P21Forth, NEXT does @A+ PUSH ;.  IP is held implicitly in the A
register.  So, I put the address I want to return to in IPNEW, and the
address of IPNEW in A, then call a P21Forth word.  By the way, the code
fragment I posted *does* work, I'm just looking for a better way.

>(2) do you really mean for this code to be non reentrant?

No, that's why I'm asking the question.  The fragment above would require
a different IPSAVE and IPNEW for each instantiation.  I'm wondering if there's
a better way.

>(3) I'm curious, is this constant code or a template?

Don't understand your question.

>(4) What are your "register conventions" for the C compiler?

Probably going to be T=accumulator, A=stack pointer.  An index register
might be kept in a VARIABLE, or in R0.

>(5) Do you care to investigate free internal stack space in the
>routines you're calling?

I'm calling Jeff's P21Forth routines.  He preserves R0=RP, T=SP, A=IP.
My call code assumes no more than that.

>(6) Don't you think that A! and + should automatically insert nops
>where needed?

Huh?  I have placed a NOP before A!, unless it is the first instruction.
This is, to my understanding, correct.

>Presuming the easy answers to these questions, I'd probably generate
>code like:
>   varref ipsave
>   varref ipnew
>   varref calladdr
>...
>   ipsave # a<->tos !a #ipnew a! #calladdr push ;' #ipsave a! @a a!

Umm, isn't this exactly what I've done above?  I'm missing your point.

-Dave