Hello,
I do know almost nothing about assembler, Lisp, Scheme or Forth. My ignorance is definitely embarrasing. By accident I read about JonesForth which is a nice tutorial and source code for Forth in Linux (public domain) written using Gnu assembler instructions. Another program is JonesForthInC for Windows using inline assembler instructions. I would like to do it with OxygenBasic and to learn about asm with o2. Of course I already have a problem with the first three instructions which are macros:
This is the code in JonesForth.s:
/* NEXT macro. */
.macro NEXT
lodsl
jmp *(%eax)
.endm
/* The macro is called NEXT. That's a FORTH-ism. It expands to those two instructions.
/* Macros to deal with the return stack. */
.macro PUSHRSP reg
lea -4(%ebp),%ebp // push reg on to return stack
movl \reg,(%ebp)
.endm
.macro POPRSP reg
mov (%ebp),\reg // pop top of return stack to reg
lea 4(%ebp),%ebp
.endm
/*
And with that we can now talk about the interpreter.
This is the code in JonesForthInC.c for Windows:
#define D DWORD PTR
/* NEXT macro. */
#define NEXT \
_asm lodsd \
_asm jmp D [eax] \
/*
The macro is called NEXT. That's a FORTH-ism. It expands to those two instructions.
* Macros to deal with the return stack. */
/*
sub ebp,4 // push reg on to return stack
mov [ebp],reg
*/
#define PUSHRSP(reg) \
_asm sub ebp,4 \
_asm mov [ebp],reg
/*
mov reg,[ebp]; // pop top of return stack to reg
add ebp,4;
*/
#define POPRSP(reg) \
_asm mov reg,[ebp] \
_asm add ebp,4
/*
And with that we can now talk about the interpreter.
This is my attempt in OxygenBasic:
/* NEXT macro. */
def NXT
lodsw
jmp [eax] ;
end def
/*
/* Is this FORTH-ish?
/* Macros to deal with the return stack. */
def PUSHRSP reg
sub ebp,4 // push reg on to return stack
mov [ebp],reg
end def
def POPRSP reg
mov reg,[ebp] // pop top of return stack to reg
add ebp,4
end def
*/
And if I ever manage this we can then talk about the interpreter. */
Is anything of this code correct? And can I later use: PUSHRSP eax? Without a little help I am lost at the beginning.
Roland