X-Git-Url: https://git.rrq.au/?a=blobdiff_plain;f=jonesforth.S;h=b7990e8cb9d0c8e12943320503f846bf8f226ad1;hb=e8aaec0eb1676422d1cda0338405c0cae8bd42a7;hp=5c1249c13ebc5d472464427fdd88cd1b0acc83e1;hpb=f288aec7ec596e7da9a0390c66517bd03ad837fd;p=rrq%2Fjonesforth.git diff --git a/jonesforth.S b/jonesforth.S index 5c1249c..b7990e8 100644 --- a/jonesforth.S +++ b/jonesforth.S @@ -1,11 +1,11 @@ /* A sometimes minimal FORTH compiler and tutorial for Linux / i386 systems. -*- asm -*- By Richard W.M. Jones http://annexia.org/forth This is PUBLIC DOMAIN (see public domain release statement below). - $Id: jonesforth.S,v 1.36 2007-09-27 23:09:39 rich Exp $ + $Id: jonesforth.S,v 1.38 2007-09-28 19:39:21 rich Exp $ gcc -m32 -nostdlib -static -Wl,-Ttext,0 -o jonesforth jonesforth.S */ - .set JONES_VERSION,36 + .set JONES_VERSION,38 /* INTRODUCTION ---------------------------------------------------------------------- @@ -757,6 +757,14 @@ code_\label : // assembler code follows push %ecx NEXT + defcode "?DUP",4,,QDUP // duplicate top of stack if non-zero + pop %eax + test %eax,%eax + jz 1f + push %eax +1: push %eax + NEXT + defcode "1+",2,,INCR incl (%esp) // increment top of stack NEXT @@ -1924,10 +1932,13 @@ _COMMA: NEXT /* - PRINTING STRINGS ---------------------------------------------------------------------- + LITERAL STRINGS ---------------------------------------------------------------------- + + LITSTRING is a primitive used to implement the ." and S" operators (which are written in + FORTH). See the definition of those operators later. - LITSTRING and EMITSTRING are primitives used to implement the ." and S" operators - (which are written in FORTH). See the definition of those operators below. + TELL just prints a string. It's more efficient to define this in assembly because we + can make it a single Linux syscall. */ defcode "LITSTRING",9,,LITSTRING @@ -1939,7 +1950,7 @@ _COMMA: andl $~3,%esi NEXT - defcode "EMITSTRING",10,,EMITSTRING + defcode "TELL",4,,TELL mov $1,%ebx // 1st param: stdout pop %edx // 3rd param: length of string pop %ecx // 2nd param: address of string