6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Apr 27, 2024 6:22 pm

All times are UTC




Post new topic Reply to topic  [ 17 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re:
PostPosted: Thu Dec 31, 2020 3:25 am 
Offline

Joined: Fri May 05, 2017 9:27 pm
Posts: 851
dclxvi wrote:
Inline assembly with ITC or DTC isn't common because, unlike STC, you don't gain much. Using a headerless code definition followed by an ordinary colon definition is often more flexible anyway. Even with something like FIG-Forth, which wasn't designed to use headerless words, it's easy to write a defining word that defines a headerless primitive. Many would argue, however, that inline assembly is a sign that you need to factor your definition.


What about inline high level Forth? Here is an example from Fleet Forth, an ITC Forth. I made (ABORT") , the word compiled by ABORT" , a primitive that has inline high level Forth.
If there is an error, the speed penalty of the high level Forth in (ABORT") is not a problem since we're aborting anyway.
If the top of stack is zero, (ABORT") increments IP past the inline string and jumps to POP, getting it's job done fast.
Since (ABORT") starts as a CODE word and stays at low level if there is no error, it greatly reduces the speed penalty of error checking.


Top
 Profile  
Reply with quote  
PostPosted: Thu May 18, 2023 12:20 am 
Offline

Joined: Fri May 05, 2017 9:27 pm
Posts: 851

A minor update. The source for my Forth's # used to be this:
Code:
HEX
: #  ( D1 -- D2 )
   BASE @ UD/MOD ROT
   INLINE
   0 ,X LDA,  0A # CMP,  CS IF,
      6 # ADC,
   THEN,
   30 # ADC,  0 ,X STA,
   END-INLINE
   HOLD ;

It is now this:
Code:
: #  ( D1 -- D2 )
   BASE @ UD/MOD ROT
   >ASSEM
   0 ,X LDA  #10 # CMP
   CS IF  6 # ADC  THEN
   #48 # ADC  0 ,X STA
   LABEL HOLD.BODY
   SEC
   ' HLD >BODY C@ # LDY
   DEX  DEX
   UP )Y LDA  1 # SBC  UP )Y STA
   0 ,X STA  INY
   UP )Y LDA  0 # SBC  UP )Y STA
   1 ,X STA
   LABEL C!.BODY
   2 ,X LDA  0 X) STA
   POPTWO JMP  END-CODE

HOLD and C! have no bodies. Their code fields point into the low level portion of # and SIGN is now a primitive.
Code:
CODE HOLD  ( C -- )
   HOLD.BODY  LATEST NAME> !
   END-CODE
CODE C!  ( C ADR -- )
   C!.BODY  LATEST NAME> !
   END-CODE
CODE SIGN  ( N -- )
   1 ,X ASL  ASCII - # LDA
   0 ,X STA
   ' HOLD @ CS BRAN
   POP JMP  END-CODE

Although # is much larger, less memory is used for these words than if # , HOLD and SIGN were high level. A savings of a few bytes and a speed up from mixing low level code in a high level word.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ]  Go to page Previous  1, 2

All times are UTC


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: