Build your own Forth for microchip PIC (Episode 839) : Forth
This is a discussion on Build your own Forth for microchip PIC (Episode 839) within the Forth forums in Programming Languages category; I've asked about a primitive kernel to implement Forth upon. Instead of looking at existing examples maybe a better approach is to post a description of my current 16F NPCI bytecode and discuss. I'll try to add typical forth stack comments for each primitive. This virtual machine implemented a frame pointer for locals and parameters. Comments as to the necessity of such a contruct welcome. -------------------------------------------------------- assign ; 0 - assign ( n1 -- ) / Badly implemented for forth address was encoded into the bytecode / need to reimplement where the address is on the stack. Should it / ...
| Forth Forth programming language |
![]() |
| | LinkBack | Thread Tools |
|
#1
| |||
| |||
| looking at existing examples maybe a better approach is to post a description of my current 16F NPCI bytecode and discuss. I'll try to add typical forth stack comments for each primitive. This virtual machine implemented a frame pointer for locals and parameters. Comments as to the necessity of such a contruct welcome. -------------------------------------------------------- assign ; 0 - assign ( n1 -- ) / Badly implemented for forth address was encoded into the bytecode / need to reimplement where the address is on the stack. Should it / be ( n1 n2 -- ) with n1 being written to n2? or vice-versa? -------------------------------------------------------- plus ; 1 - plus ( n1 n2 -- n1 + n2 ) -------------------------------------------------------- equal ; 2 - equal ( n1 n2 -- n1 == n2 ) / All logical ops current use C style 0 for false, everything else / is true. In addition returns 1 on stack for true. Is there a / better implementation? -------------------------------------------------------- notequal ; 3 - notequal ( n1 n2 -- n1 != n2 ) -------------------------------------------------------- minus ; 4 - minus ( n1 n2 -- n2 - n1 ) -------------------------------------------------------- bitand ; 5 - bitand ( n1 n2 -- n1 & n2 ) -------------------------------------------------------- bitor ; 6 - bitor ( n1 n2 -- n1 | n2 ) -------------------------------------------------------- bitxor ; 7 - bitxor ( n1 n2 -- n1 ^ n2 ) -------------------------------------------------------- logior ; 8 - logical or ( n1 n2 -- n1 || n2 ) -------------------------------------------------------- logiand ; 9 - logical and ( n1 n2 -- n1 && n2 ) -------------------------------------------------------- procret ; 10 - return from procedure ( n1 -- ) / NPCI didn't have a separate return stack. So the return address / is pulled off the only stack available. Needs to be reimplemented / but fundamentally this is EXIT. Pulled return address off stack / and put in IP -------------------------------------------------------- callproc ; 11 - call procedure ( -- n1 ) / Same here. Pushed return address on stack and jumped to address / encoded after bytecode. Needs to be reimplemented for typical / FORTH inner loop. Fundamentally is ENTER. -------------------------------------------------------- shiftleft ; 12 - shift left ( n1 n2 -- n2 << n1 ) / No rotate. shift only -------------------------------------------------------- shiftright ; 13 - shift right ( n1 n2 -- n2 >> n1 ) / No rotate. shift only -------------------------------------------------------- greater ; 14 - greater ( n1 n2 -- n2 > n1 ) / Same as equals in terms of results -------------------------------------------------------- less ; 15 - less than ( n1 n2 -- n2 < n1 ) / Same as equals in terms of results -------------------------------------------------------- greatereq ; 16 - greater than or equals ( n1 n2 -- n2 >= n1 ) / Same as equals in terms of results -------------------------------------------------------- lesseq ; 17 - less than or equals ( n1 n2 -- n2 <= n1 ) / Same as equals in terms of results -------------------------------------------------------- bitval ; 18 - Get bit value ( n1 -- n1 ) / Needs to be reimplemented. Gets the value of bit on TOS. / variable address currently implemented in bytecode and needs to be / moved to the stack. -------------------------------------------------------- bitassign ; 19 - Assign bit ( n1 n2 -- ) / Needs to be reimplemented. sets the value of bit on TOS to value // underneath in n2. / variable address currently implemented in bytecode and needs to be / moved to the stack. -------------------------------------------------------- not ; 20 - Logical not - ( n1 -- !n1 ) // Use xor 255 for bitwise -------------------------------------------------------- dotable ; 21 - Access table. ( n1 -- n1 ) / probable needs reimplementation. Fetches byte from table in program / memory. Table base encoded in bytecode. incoming n1 is index. Outgoing / is value. Used for static tables. Probably can be dropped for forth. -------------------------------------------------------- pushfpval ; 22 - Push a frame pointer val on stack ( n1 -- n1 ) / Uses frame pointer. Not sure forth needs it -------------------------------------------------------- pushfpref ; 23 - Push a frame pointer ref on stack ( n1 -- n1 ) / Uses frame pointer. Not sure forth needs it -------------------------------------------------------- assignfp ; 24 - Assign to a frame pointer variable ( n1 n2 -- ) / Uses frame pointer. Not sure forth needs it / May implement bit assign better than original because address is on / the stack. -------------------------------------------------------- bassignfp ; 25 - Assign to a frame pointer varaiable bit ( n1 n2 n3 -- ) / Uses frame pointer. Not sure forth needs it / May implement bit assign better than original because address is on / the stack. -------------------------------------------------------- link ; 26 - Save old fp on TOS and point FP to TOS ( -- n1 ) -------------------------------------------------------- unlink ; 27 - Restore FP to previous value. ( n1 -- ) -------------------------------------------------------- movetos ; 28 - move the stack pointer number of bytes ; specified by value on TOS ( n1 -- variable drop ) -------------------------------------------------------- charmode ; 29 - Set stack to 8 bit mode ( -- ) / impements 8 bit stack unneccary for forth -------------------------------------------------------- intmode ; 30 - Set stack to 16 bit mode / impements 16 bit stack unneccary for forth -------------------------------------------------------- stackadj ; 31 - Adjust stack making second op into int. ; presumes that top op is already an int. / intmode/charmode conversion. unnecessary for forth -------------------------------------------------------- numbers ; push number on the stack ( -- n1 ) -------------------------------------------------------- variables ; push contents of memory on stack ( -- n1 ) needs to be reimplemented as target address not on stack -------------------------------------------------------- conditional goto; jump if TOS is 0 ( n1 -- ) Needs to be reimplemented because target address not on stack. -------------------------------------------------------- goto ; jump to target ( -- ) Needs to be reimplemented because target address not on stack -------------------------------------------------------- If anyone gets a chance, take a look and tell me what you think. All of these are coded and tested in PIC 16F assembly. Thanks, BAJ |
|
#2
| |||
| |||
| none Byron Jeff wrote: [snipped] Byron, could I ask you reply to your own root post? Then each of these wouldn't end up as a seperate thread; they really belong together. Thanks -- Regards Alex McDonald |
|
#3
| |||
| |||
| In article <A7GdnZLZNr_ZMODbnZ2dnUVZ8qPinZ2d@bt.com>, Alex McDonald <blog@rivadpm.com> wrote: >none Byron Jeff wrote: > >[snipped] > >Byron, could I ask you reply to your own root post? Then each of these >wouldn't end up as a seperate thread; they really belong together. I thought of them as separate issues personally. But if that's what you would prefer. Will do. BAJ |
|
#4
| |||
| |||
| none Byron Jeff wrote: > In article <A7GdnZLZNr_ZMODbnZ2dnUVZ8qPinZ2d@bt.com>, > Alex McDonald <blog@rivadpm.com> wrote: >> none Byron Jeff wrote: >> >> [snipped] >> >> Byron, could I ask you reply to your own root post? Then each of these >> wouldn't end up as a seperate thread; they really belong together. > > I thought of them as separate issues personally. But if that's what you > would prefer. Will do. > > BAJ A threaded newsreader makes it easier to see the flow, and will save you (and your readers) the effort of repetition. I'm interested in what you're doing, hence the request. -- Regards Alex McDonald |
|
#5
| |||
| |||
| In article <D4-dndFfGqbKLuDbRVnyvQA@bt.com>, Alex McDonald <blog@rivadpm.com> wrote: >none Byron Jeff wrote: >> In article <A7GdnZLZNr_ZMODbnZ2dnUVZ8qPinZ2d@bt.com>, >> Alex McDonald <blog@rivadpm.com> wrote: >>> none Byron Jeff wrote: >>> >>> [snipped] >>> >>> Byron, could I ask you reply to your own root post? Then each of these >>> wouldn't end up as a seperate thread; they really belong together. >> >> I thought of them as separate issues personally. But if that's what you >> would prefer. Will do. >> >> BAJ > >A threaded newsreader makes it easier to see the flow, and will save you >(and your readers) the effort of repetition. I'm interested in what >you're doing, hence the request. I have a threaded newsreader. Again I just felt they were separate topics of discussion and didn't want to get multiple threads muddled together into a single tangled ball. BAJ |
|
#6
| |||
| |||
| none Byron Jeff wrote: > In article <D4-dndFfGqbKLuDbRVnyvQA@bt.com>, > Alex McDonald <blog@rivadpm.com> wrote: >> none Byron Jeff wrote: >>> In article <A7GdnZLZNr_ZMODbnZ2dnUVZ8qPinZ2d@bt.com>, >>> Alex McDonald <blog@rivadpm.com> wrote: >>>> none Byron Jeff wrote: >>>> >>>> [snipped] >>>> >>>> Byron, could I ask you reply to your own root post? Then each of these >>>> wouldn't end up as a seperate thread; they really belong together. >>> I thought of them as separate issues personally. But if that's what you >>> would prefer. Will do. >>> >>> BAJ >> A threaded newsreader makes it easier to see the flow, and will save you >> (and your readers) the effort of repetition. I'm interested in what >> you're doing, hence the request. > > I have a threaded newsreader. Again I just felt they were separate > topics of discussion and didn't want to get multiple threads muddled > together into a single tangled ball. If they were different topics, they'd have different, more relevant subject lines, rather than the artificial distinction of a phony number. Cheers, Elizabeth -- ================================================== Elizabeth D. Rather (US & Canada) 800-55-FORTH FORTH Inc. +1 310-491-3356 5155 W. Rosecrans Ave. #1018 Fax: +1 310-978-9454 Hawthorne, CA 90250 http://www.forth.com "Forth-based products and Services for real-time applications since 1973." ================================================== |
|
#7
| |||
| |||
| On Sat, 23 Jun 2007 18:25:20 -0500, byron@upstairs.(none) (Byron Jeff) wrote: >I've asked about a primitive kernel to implement Forth upon. Instead of >looking at existing examples maybe a better approach is to post a >description of my current 16F NPCI bytecode and discuss. I'll try to add >typical forth stack comments for each primitive. This virtual machine >implemented a frame pointer for locals and parameters. Comments as to >the necessity of such a contruct welcome. If you haven't already done so, have a look at the Open Terminal Architecture (OTA) specifications. This wa the result of a work by Forth Inc and MPE for Europay, now part of MasterCard. OTA is basically a two-stack VM based on Forth, extended for C, and focussed on code density. Google tells me that you can find the documents at: www.forth.org.ru/~mlg/std/OTA/ Stephen -- Stephen Pelc, stephenXXX@mpeforth.com MicroProcessor Engineering Ltd - More Real, Less Time 133 Hill Lane, Southampton SO15 5AF, England tel: +44 (0)23 8063 1441, fax: +44 (0)23 8033 9691 web: http://www.mpeforth.com - free VFX Forth downloads |
|
#8
| |||
| |||
| Op Sat, 23 Jun 2007 18:25:20 -0500 schreef none: > I've asked about a primitive kernel to implement Forth upon. Instead of > looking at existing examples maybe a better approach is to post a > description of my current 16F NPCI bytecode and discuss. I'll try to add > typical forth stack comments for each primitive. This virtual machine > implemented a frame pointer for locals and parameters. Comments as to > the necessity of such a contruct welcome. > > -------------------------------------------------------- > assign ; 0 - assign ( n1 -- ) > > / Badly implemented for forth address was encoded into the bytecode > / need to reimplement where the address is on the stack. Should it > / be ( n1 n2 -- ) with n1 being written to n2? or vice-versa? > -------------------------------------------------------- > plus ; 1 - plus ( n1 n2 -- n1 + n2 ) > -------------------------------------------------------- > equal ; 2 - equal ( n1 n2 -- n1 == n2 ) > > / All logical ops current use C style 0 for false, everything else > / is true. In addition returns 1 on stack for true. Is there a > / better implementation? > -------------------------------------------------------- > notequal ; 3 - notequal ( n1 n2 -- n1 != n2 ) > -------------------------------------------------------- > minus ; 4 - minus ( n1 n2 -- n2 - n1 ) I think you have the stack reversed from the normal Forth notation ( n1 n2 -- n1-n2 ) Push n1 first, than n2, and subtracht n2 from n1. > -------------------------------------------------------- > bitand ; 5 - bitand ( n1 n2 -- n1 & n2 ) > -------------------------------------------------------- > bitor ; 6 - bitor ( n1 n2 -- n1 | n2 ) > -------------------------------------------------------- > bitxor ; 7 - bitxor ( n1 n2 -- n1 ^ n2 ) > -------------------------------------------------------- > logior ; 8 - logical or ( n1 n2 -- n1 || n2 ) > -------------------------------------------------------- > logiand ; 9 - logical and ( n1 n2 -- n1 && n2 ) > -------------------------------------------------------- > procret ; 10 - return from procedure ( n1 -- ) > > / NPCI didn't have a separate return stack. So the return address > / is pulled off the only stack available. Needs to be reimplemented > / but fundamentally this is EXIT. Pulled return address off stack > / and put in IP > -------------------------------------------------------- > callproc ; 11 - call procedure ( -- n1 ) > > / Same here. Pushed return address on stack and jumped to address > / encoded after bytecode. Needs to be reimplemented for typical > / FORTH inner loop. Fundamentally is ENTER. > -------------------------------------------------------- > shiftleft ; 12 - shift left ( n1 n2 -- n2 << n1 ) Reverse the stack: ( n1 n2 -- n1<<n2 ) > / No rotate. shift only > -------------------------------------------------------- > shiftright ; 13 - shift right ( n1 n2 -- n2 >> n1 ) Idem dito. n1<<n2 > / No rotate. shift only > -------------------------------------------------------- > greater ; 14 - greater ( n1 n2 -- n2 > n1 ) > n1<n2 I could go on, but I'm going to eat my vanilla yoghurt ;-) -- Coos CHForth, 16 bit DOS applications http://home.hccnet.nl/j.j.haak/forth.html |
|
#9
| |||
| |||
| In article <1sxqxtculdr4m$.1ly164xd3gegw$.dlg@40tude.net>, Coos Haak <chforth@hccnet.nl> wrote: >Op Sat, 23 Jun 2007 18:25:20 -0500 schreef none: > >> I've asked about a primitive kernel to implement Forth upon. Instead of >> looking at existing examples maybe a better approach is to post a >> description of my current 16F NPCI bytecode and discuss. >> minus ; 4 - minus ( n1 n2 -- n2 - n1 ) > >I think you have the stack reversed from the normal Forth notation >( n1 n2 -- n1-n2 ) >Push n1 first, than n2, and subtracht n2 from n1. You are correct. My NPCI compiler converts infix to postfix using a operator stack. Operands pass through unmodified. I misunderstood where the TOS is. I just finished reading the gforth manual. TOS is furthest to the right, not the left. Got it. BTW the primitives do implement the proper stack effect. I get a D- for listing them incorrectly. Sorry. BAJ |
![]() |
| Thread Tools | |
| |
| ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| ADO episode | usenet | ADO DAO RDO RDS | 5 | 10-05-2007 10:35 AM |
| Build your own Forth for Microchip PIC (Episode 837) | usenet | Forth | 95 | 07-21-2007 10:06 AM |
| Build your own Forth for Microchip PIC (Episode 838): Threading | usenet | Forth | 12 | 06-24-2007 06:56 PM |
| [RBtv] Episode 4: Entering the Tic Tac Factory | usenet | basic.visual | 0 | 06-08-2007 07:05 PM |
| Re: Build your own Forth for Microchip PIC: the nature of metacompilation | usenet | Forth | 0 | 01-01-1970 12:00 AM |


