From c1b6bdca4f63faec8c041ffe2bbf043f36638bd0 Mon Sep 17 00:00:00 2001 From: rich Date: Fri, 7 Sep 2007 23:28:50 +0000 Subject: [PATCH] ALLOT, +!, -! --- jonesforth.S | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) 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 \" -- 1.8.3.1