6502 Assembler in 96 lines of Forth (July 1980)

Topics relating to various Forth models on the 6502, 65816, and related microprocessors and microcontrollers.
chitselb
Posts: 232
Joined: 21 Aug 2010
Location: Ontonagon MI
Contact:

Re: 6502 Assembler in 96 lines of Forth (July 1980)

Post by chitselb »

JimBoyd wrote:
The assembler I wrote for my Forth for the Commodore 64 is also based on Ragsdale's assembler. I rewrote M/CPU and the index table is ten bytes smaller. I added range checking for the instructions that compile a branch. One change I'm thinking about is removing the comma's at the end of the opcode and control structure names. On the other hand, the code words for the system are written with the comma's in the names and I'd have to rewrite it.
I squeezed it down a bit in PETTIL too. The best reason to leave the commas at the end of the opcodes is that it's how most other RPN Forth Assembly language is written.
JimBoyd
Posts: 931
Joined: 05 May 2017

Re: 6502 Assembler in 96 lines of Forth (July 1980)

Post by JimBoyd »

chitselb wrote:
The best reason to leave the commas at the end of the opcodes is that it's how most other RPN Forth Assembly language is written.
Thank you! I don't have experience with other RPN Forth assemblers. I will keep the commas.
JimBoyd
Posts: 931
Joined: 05 May 2017

Re: 6502 Assembler in 96 lines of Forth (July 1980)

Post by JimBoyd »


Does anyone know of any bugs in Ragsdale's assembler?
Blazin' Forth's assembler is based on Ragsdale's and the creator of Blazin' Forth said the following.
Scott Ballantyne wrote:
Actually, there was only one bug ever reported from Blazin' Forth, and I found that myself and uploaded a patch. To tell the truth, there is one other bug in that program, I discovered it years later. It's actually a bug in the assembler - there was a garbage line that should have triggered an error but didn't, it assembled garbage. But the nature of the bug is such that it actually is only triggered extremely rarely. No one has ever reported it. Hehe!

I don't know if he was referring to:
1) The assembler he used to build Blazin' Forth and the bug is in Blazin' Forth.
2) The assembler he included with Blazin' Forth which is based on Ragsdale's.
User avatar
GARTHWILSON
Forum Moderator
Posts: 8773
Joined: 30 Aug 2002
Location: Southern California
Contact:

Re: 6502 Assembler in 96 lines of Forth (July 1980)

Post by GARTHWILSON »

chitselb wrote:
The best reason to leave the commas at the end of the opcodes is that it's how most other RPN Forth Assembly language is written.
Which ones have you used? Besides my own, the only one I've used, which was a metacompiler, did this kind of thing:

Code: Select all

( d1 d2 -- f )
CODE D=         TOS 0 + LDA     TOS 4 + CMP     1$ BNE
                TOS 1 + LDA     TOS 5 + CMP     1$ BNE
                TOS 2 + LDA     TOS 6 + CMP     1$ BNE
                TOS 3 + LDA     TOS 7 + CMP     1$ BNE
                POP3-TRUE  JMP
        1$:     POP3-FALSE JMP  END-CODE

No commas. I don't remember any in Forth Dimensions magazine using commas either; but I'd have to look through a lot of old issues to make sure that's true.
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
JimBoyd
Posts: 931
Joined: 05 May 2017

Re: 6502 Assembler in 96 lines of Forth (July 1980)

Post by JimBoyd »


Interesting. I just got an idea on how to write an editor tool to automate the task of changing the comma terminated version of the mnemonics and control flow words to a version without commas yet it will not affect any other words with commas. I think I'll get rid of those commas after all.
JimBoyd
Posts: 931
Joined: 05 May 2017

Re: 6502 Assembler in 96 lines of Forth (July 1980)

Post by JimBoyd »


I ran into a minor issue which I mention here.
JimBoyd
Posts: 931
Joined: 05 May 2017

Re: 6502 Assembler in 96 lines of Forth (July 1980)

Post by JimBoyd »

JimBoyd wrote:
chitselb wrote:
The best reason to leave the commas at the end of the opcodes is that it's how most other RPN Forth Assembly language is written.
Thank you! I don't have experience with other RPN Forth assemblers. I will keep the commas.

I removed the commas from my assembler about two years ago and do not miss them.
This reads much nicer

Code: Select all

CODE BOUNDS  ( N1 N2 -- N1+N2 N1 )
   CLC
   0 ,X LDA  2 ,X ADC  0 ,X STA
   1 ,X LDA  3 ,X ADC  1 ,X STA
   ' SWAP @ JMP  END-CODE

than this

Code: Select all

CODE BOUNDS  ( N1 N2 -- N1+N2 N1 )
   CLC,
   0 ,X LDA,  2 ,X ADC,  0 ,X STA,
   1 ,X LDA,  3 ,X ADC,  1 ,X STA,
   ' SWAP @ JMP,  END-CODE

and it's faster to type.
Post Reply