X-Git-Url: https://git.rrq.au/?a=blobdiff_plain;f=jonesforth.S;h=e82bd1fc921d2fab5d62418af34daed0dd7c2fd7;hb=c1b6bdca4f63faec8c041ffe2bbf043f36638bd0;hp=11b0cfd163b46a8b2fa5bdae4424ca3a405a2619;hpb=5d5f02cd86cf885be486427a450b999086c6b1ec;p=rrq%2Fjonesforth.git diff --git a/jonesforth.S b/jonesforth.S index 11b0cfd..e82bd1f 100644 --- a/jonesforth.S +++ b/jonesforth.S @@ -1,4 +1,4 @@ -/* A minimal FORTH interpreter for Linux / i386 systems. -*- asm -*- +/* A somewhat minimal FORTH interpreter for Linux / i386 systems. -*- asm -*- * By Richard W.M. Jones * * gcc -m32 -nostdlib -static -Wl,-Ttext,0 -o jonesforth jonesforth.S @@ -317,9 +317,22 @@ var_\name : push %eax // push value onto stack NEXT + defcode "+!",2,ADDSTORE + pop %ebx // address + pop %eax // the amount to add + addl %eax,(%ebx) // add it + NEXT + + defcode "-!",2,SUBSTORE + pop %ebx // address + pop %eax // the amount to subtract + subl %eax,(%ebx) // add it + NEXT + /* ! and @ (STORE and FETCH) store 32-bit words. It's also useful to be able to read and write bytes. * I don't know whether FORTH has these words, so I invented my own, called !b and @b. * Byte-oriented operations only work on architectures which permit them (i386 is one of those). + * UPDATE: writing a byte to the dictionary pointer is called C, in FORTH. */ defcode "!b",2,,STOREBYTE pop %ebx // address to store at @@ -930,7 +943,7 @@ buffer: DUP '\"' <> WHILE HERE @ !b \\ store the character in the compiled image - HERE @ 1+ HERE ! \\ increment HERE pointer by 1 byte + HERE 1 +! \\ increment HERE pointer by 1 byte REPEAT DROP \\ drop the double quote character at the end DUP \\ get the saved address of the length word @@ -969,6 +982,10 @@ buffer: , \\ compile it ; +\\ ALLOT is used to allocate (static) memory when compiling. It increases HERE by +\\ the amount given on the stack. +: ALLOT HERE +! ; + \\ Finally print the welcome prompt. .\" OK \"