embedded systems developers tools, cross compilers
  Home  |   SwiftX Archive  |   SwiftForth Archive  |

COMPARE Full Length

From: Bulgrien, Dennis <DBulgrien_at_vcsd.com>
Date: Tue, 17 Sep 2002 08:07:04 -0500

Why must I COMPARE one less than the length of a string for it to recognize
a match? I create two strings in the target image, $Revision being the
shorter one to match, $Revision2 being the longer one to scan. At compile
time the longer one is scanned with a DO loop starting from the first
character address. If the shorter is found at the I'th position it is
DUMPC'ed.

TARGET
S" $Revision:x" DUP 1+ ALLOT 2CONSTANT $Revision
S" x$Revision:x1" DUP 1+ ALLOT 2CONSTANT $Revision2
INTERPRETER
: $Revision, $Revision2 OVER + SWAP ?DO $Revision { 1- } I OVER COMPARE DUP
0= IF I 13 DUMPC DROP ELSE CR . THEN LOOP ;
$Revision,

Without 1- :
-1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1

With 1- :
-1
120CB 24 52 65 76 69 73 69 6F 6E 3A 78 31 FF $Revision:x1.
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
----------------------------------------------------------------------
swiftx_at_forth.com The SwiftX programming discussion email list
To unsubscribe, send subject "unsubscribe swiftx" to listar_at_forth.com
For help with listar commands, send subject "help" to listar_at_forth.com
Archives are located at http://www.forth.com/swiftx -- check them out!
----------------------------------------------------------------------
THIS LIST IS NOT FOR BUG REPORTS! Send bug reports to support_at_forth.com.
Received on Tue Sep 17 2002 - 06:05:06 PDT

This archive was generated by hypermail 2.2.0 : Mon Dec 01 2008 - 03:04:47 PST