6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Nov 16, 2024 12:20 pm

All times are UTC




Post new topic Reply to topic  [ 34 posts ]  Go to page Previous  1, 2, 3
Author Message
PostPosted: Tue Jun 07, 2016 3:20 pm 
Offline

Joined: Fri Jun 03, 2016 3:42 am
Posts: 158
BitWise wrote:
Hugh Aguilar wrote:
Would you agree that pretty much every Forth compiler-writer makes the pointer registers 8-bit and only the accumulator 16-bit?

My 65C816 DTC Forth keeps all the registers in 16-bit mode and only changes A to 8-bits when accessing byte variables. It also uses DP as the data stack pointer.

The 65C816 supports many different register organisations for Forth, each with its own trade offs.

Well, using DP as the data-stack pointer will work. I would consider this in a Forth that is to be used on a desktop-computer such as the Apple-IIgs.

I would be pretty dubious of this technique in a Forth that is to be used in a micro-controller. In this case, you typically have a small program and it uses a lot of global variables. Most of the I/O ports are going to have a circular-buffer associated with them. You need pointers to the next-available-to-store and the next-available to next-available-to-load locations in the buffer. You also need pointers to the base and limit addresses of the buffer --- these are constants if the buffer is allotted memory at compile-time, but are global variables if the buffer is allocated memory at run-time. The program is going to be sped up considerably if all of these pointers are global variables in the direct-page. In most micro-controller programs, over half of the time is spent servicing interrupts, and all of the ISRs data has to be stored in global variables because that is the only way for ISRs to communicate with the main-program. Also, the ISRs speed will be boosted considerably if all of the I/O ports are in the direct-page too.

The 8051 was used for a long time and the majority of programs only used the direct-page and did not use external memory at all.


Top
 Profile  
Reply with quote  
PostPosted: Tue Jul 12, 2016 7:33 pm 
Offline

Joined: Sat Aug 21, 2010 7:52 am
Posts: 231
Location: Arlington VA
Here's 'C@X', written using the split stack (sans 16-bit TOS z.p. register) and incorporating Hugh's idea of overwriting the half-stack to use (zp,X) addressing. '@X' would be similar, with the aforementioned penalty of doing a 16-bit increment (of stackl,x and stackl+1,x in this model). It comes out to 15 bytes, the same as 'C@' in the code Mike posted below.

The advantage of this method is I don't spend clock cycles copying things in and out of TOS.

To me this feels cumbersome vs. using the (zp),Y addressing mode I get, along with Sweet-16's sixteen 16-bit registers in 00..1F (PETTIL's TOS overlaps R1 at 02..03). PETTIL also lets primitives use this 32-byte area for my version of local variables.


I looked at a few different ways of doing the data stack in PETTIL before picking the way I did, probably because reading this article sold me on the split stack with a unified TOS.

Code:
;--------------------------------------------------------------
#if 0
name=C@X
stack=( addr -- byte )

Like `C@`, but uses (zp,X) addressing mode in an imaginary
PETTIL environment where I rewrite everything else too
#endif
cfetchx
    ldy stackl+1,x
    lda stackh,x
    sta stackl+1,x
    lda (stackl,x)
    sty stackl+1,x
    ldy #0
    jmp put


barrym95838 wrote:
IMO, Charlie is doing some very nice work with only NMOS instructions in his PETTIL project. Here's a sample from here:
Code:

;--------------------------------------------------------------
#if 0
name=@
stack=( addr -- 16b )
tags=forth-79,nucleus,memory,fig,forth-83
Leave the 16 bit contents of address.

!!! pronounced:"fetch"
  16b is the value at addr.
#endif
fetch
    sec
    .byt $29        ; AND #
;--------------------------------------------------------------
#if 0
name=C@
stack=( addr -- 8b )
tags=forth-79,nucleus,memory


!!! pronounced: "c-fetch"
 8b is the contents of the byte at addr.

#endif
cfetch
    clc
cfetch01
    ldy #0
    lda (tos),y
    bcc put
    pha
    iny
    lda (tos),y
    tay
    pla
    bcs put

;--------------------------------------------------------------

I believe he has spent quality time making the split-dictionary and split-stack with separate TOS work ... he's a very good NMOS coder, IMO. If you have carnal knowledge of your system, you can even do things to make it more efficient, like doing a NIP DROP instead of a DROP DROP (Charlie's NIP is INX).

My 65m32 DTC Forth has a single machine instruction NEXT, and a whole bunch of primitives ( enter branch + 0< 1+ 1- 2* 2/ >R @ AND DROP DUP EXIT INVERT NEGATE OR R> SWAP UNLOOP XOR [ ] NIP RDROP 2RDROP ... I'm sure that I'm forgetting a few others) that are one machine instruction plus NEXT. That kind of screams out for a change to STC with in-lining, but I am floundering in an endless sea of incomplete projects, so this one will have to get pushed back at least until my house is ready for winter. I estimate that I have a couple of hundred man-hours of work to do on the house, and I only have Sundays to do it (my six-day-a-week job exhausts me to the point that I can't do much at night, and I can only afford to hire amateur help). I also estimate that I have a couple of hundred hours of work to do on the 65m32 simulator, assembler, and minimal operating system (probably Forth) before I can even consider trying to implement it on an FPGA board. It most certainly doesn't matter how slick my system software is with no processor on which to run it. Ay, Chihuahua ...

Mike B.


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 30, 2017 11:58 am 
Offline

Joined: Thu Mar 30, 2017 11:17 am
Posts: 1
Isys FORTH was advertised regularly in Call APPLE magazine. It shipped with a printed manual that described the software but an excellent tutorial on FORTH. The flippy disk had versions for 6502 'C02 'C802 and 'C816. The dev system was hands down the finest piece of software that I have ever used. Editor was very nice and it used a FORTH orthodox block disk access system. Excellent tutorial on using fixed point math for engineering and scientific applications.
Author was Bob Illyes, a great guy who worked on an assignment with me in London solving a train control problem.
Bob sold his car to buy an Apple ][, then contracted the flu. While laid up in bed, he wrote Isys FORTH.
To this day, and after using all kinds of dev systems, Isys FORTH stands out to me as the finest piece of development software ever written.


Top
 Profile  
Reply with quote  
PostPosted: Sun May 07, 2017 5:07 pm 
Offline

Joined: Fri Jun 03, 2016 3:42 am
Posts: 158
rkondra wrote:
Isys FORTH was advertised regularly in Call APPLE magazine. It shipped with a printed manual that described the software but an excellent tutorial on FORTH. The flippy disk had versions for 6502 'C02 'C802 and 'C816. The dev system was hands down the finest piece of software that I have ever used. Editor was very nice and it used a FORTH orthodox block disk access system. Excellent tutorial on using fixed point math for engineering and scientific applications.
Author was Bob Illyes, a great guy who worked on an assignment with me in London solving a train control problem.
Bob sold his car to buy an Apple ][, then contracted the flu. While laid up in bed, he wrote Isys FORTH.
To this day, and after using all kinds of dev systems, Isys FORTH stands out to me as the finest piece of development software ever written.


Thanks for posting the info on Bob Illyes --- I had forgotten his name.

That is quite a compliment to say that Isys Forth was:
"the finest piece of development software ever written."
:-)

Even today I still use this code, which I got from the Isys manual, as an example of good-style Forth:

: par ( r1 r2 -- r ) \ parallel resistance
2dup + */ ;

: par3 \ r1 r2 r3 -- r \ calculate parallel resistance of three resistors
par par ;

Writing this using local variables significantly increases the complexity. Also, there is the issue that languages such as C etc. lack mixed-precision arithmetic, so they would have to do the whole calculation in double-precision at a huge cost in speed.

I'm not opposed to local variables though --- I'm not a "fundamentalist" --- I'm just saying that they shouldn't be used gratuitously, and doing so is usually the sign of a recalcitrant C programmer who is trying to turn Forth into an rpn version of C.


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 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: