Re: [colorforth] convergence
- Subject: Re: [colorforth] convergence
- From: Eric Laforest <ecl@xxxxxxxxxxx>
- Date: Sat, 6 Mar 2004 08:10:39 -0500
On Fri, Mar 05, 2004 at 08:30:45PM -0800, Samuel A. Falvo II thus spake:
> On Friday 05 March 2004 06:58 pm, Eric Laforest wrote:
> > Also, I'm almost done (hopefully) a Machine Forth-like setup for the
> > 6502. 99 primitives written, a few more to go, then I get onto the
>
> This is amusing, considering the 6502 only has 62 opcodes (according to
> Western Design Center). :-)
Some Forth operations like 2* translate directly, and some like 2/ don't:
TWOSTAR macro
asl A ; "2*" ( n - n<<1, n0<-0 )
endm
TWOSLASH macro
cmp #$80 ; -128, so Carry = n[7]
ror A ; "2/" ( n - n>>1, n7->n7 )
endm
http://pet.dhs.org/~ecl/log/200307/2003_07_29-OnProgramming.html
And then there are the signed and unsigned versions where it matters:
UTWOSLASH macro ; "U2/" ( n - n>>1, 0->n7 )
lsr A
endm
Then double all that for double-cell numbers.
It all adds up quickly.
I'm bothering with all the variants since I have 8kB to play with, and
because I think it's a good thing to try and use as much of the hardware
capabilities as possible, given there will be no CODE words.
Nothing intrinsic prevents them, but I don't want to bother with
having to write an assembler, and it would detract from abstraction.
> I've examined the machine architecture of the 6502, and well, it's not
> really conducive to MachineForth concepts. SOME things apply, but
> compared even to x86, it really is most happy with a more traditional
> Forth implementation, I think. This is largely due to the fact that
> virtually every 6502 instruction affects the CPU flags. It makes things
> difficult sometimes.
Not at all. Most of the time, the flags are ignored.
Where they matter, and are not properly set "for free" by prior stack
manipulations (stack is in Zero Page, Accumulator is Top, X is index), I have to
do 'cmp #$00' to set them relative to the contents of the Accumulator.
This is needed for the four JMP variants and in ABS.
The downside is that conditionnal branches are relative to +/-128 bytes,
and so the JMP words wrap them around a 'jmp' opcode to make conditional
branching absolute.
--
Eric LaForest
http://pet.dhs.org/~ecl/
---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@xxxxxxxxxxxxxxxxxx
For additional commands, e-mail: colorforth-help@xxxxxxxxxxxxxxxxxx
Main web page - http://www.colorforth.com