Assembler with structured conditionals
Posted: Sun Nov 04, 2018 11:54 pm
[Edit: this is the latest version of Fleet Forth's assembler.
The original version is three posts down
Forth assemblers with structured conditionals have served me well over the years, but I've recently noticed that they can have their shortcomings. I'd like to start a discussion on how to improve an assembler with structured conditionals.
I have three examples of the word (EXPECT) from my Forth's kernel. At the start of the loop if the y-register equals the value in N, the goal is to branch to the JSR to FFCF, one of the routines in the C64 kernel.
The first two examples use various control flow stack manipulators, CS-ROT,CS-SWAP, etc. to manipulate the control flow information.
The final example was some prototyping for another approach. It makes use of the four unused bytes at 3FC-3FF. The idea is that there could be an array of available memory locations for control flow data. The words to access this memory could be:
Used as:
Any comments?
I know this approach doesn't look very Forthy, and would appreciate it if anyone has other ideas to improve an assembler with structured conditionals.
The original version is three posts down
Forth assemblers with structured conditionals have served me well over the years, but I've recently noticed that they can have their shortcomings. I'd like to start a discussion on how to improve an assembler with structured conditionals.
I have three examples of the word (EXPECT) from my Forth's kernel. At the start of the loop if the y-register equals the value in N, the goal is to branch to the JSR to FFCF, one of the routines in the C64 kernel.
The first two examples use various control flow stack manipulators, CS-ROT,CS-SWAP, etc. to manipulate the control flow information.
Code: Select all
// (EXPECT)
HEX
CODE (EXPECT) ( ADR CNT -- )
2 # LDA, SETUP JSR,
XSAVE STX, SPAN 1+ STY,
BEGIN,
N CPY,
0= WHILE,
N 1+ LDA,
0= NOT WHILE,
N 1+ DEC,
CS-ROT THEN,
0FFCF JSR, // CHRIN
0D # CMP,
0= NOT WHILE,
N 2+ )Y STA,
INY,
CS-DUP 0= UNTIL,
N 3 + INC, SPAN 1+ INC,
REPEAT,
THEN,
SPAN STY, XSAVE LDX,
NEXT JMP,
END-CODE
' (EXPECT) IS EXPECT
HEX
CODE (EXPECT) ( ADR CNT -- )
2 # LDA, SETUP JSR,
XSAVE STX, SPAN 1+ STY,
BEGIN,
N CPY,
0= IF,
N 1+ LDA,
0= NOT WHILE,
N 1+ DEC,
THEN, CS-SWAP
0FFCF JSR, // CHRIN
0D # CMP,
0= NOT WHILE,
N 2+ )Y STA,
INY,
CS-DUP 0= UNTIL,
N 3 + INC, SPAN 1+ INC,
REPEAT,
THEN,
SPAN STY, XSAVE LDX,
NEXT JMP,
END-CODE
Code: Select all
CS! ( CONTROL-FLOW-DATA SLOT-NUMBER -- )
CS@ ( SLOT-NUMBER -- CONTROL-FLOW-DATA )
Code: Select all
IF, 0 CS!
.
.
0 CS@ THEN,
Code: Select all
// (EXPECT)
HEX
CODE (EXPECT) ( ADR CNT -- )
2 # LDA, SETUP JSR,
XSAVE STX, SPAN 1+ STY,
BEGIN,
N CPY,
0= IF, 3FC 2!
N 1+ LDA,
0= NOT WHILE,
N 1+ DEC,
3FC 2@ THEN,
0FFCF JSR, // CHRIN
0D # CMP,
0= NOT WHILE,
N 2+ )Y STA,
INY,
CS-DUP 0= UNTIL,
N 3 + INC, SPAN 1+ INC,
REPEAT,
THEN,
SPAN STY, XSAVE LDX,
NEXT JMP,
END-CODE
I know this approach doesn't look very Forthy, and would appreciate it if anyone has other ideas to improve an assembler with structured conditionals.