WITHIN was meant to replace BETWEEN but it hasn't always
been a comfortable fit.
A characteristic of WITHIN is that the upper limit is not included
in the range. This can lead to obfuscated code e.g.
CHAR a CHAR z 1+ WITHIN
Thus the functionality of BETWEEN is still being used, if not
the word itself. When defined today, it is usually as:
: BETWEEN ( n1|u1 n2|u2 n3|u3 -- flag ) 1+ WITHIN ;
But it is not without problem e.g. it fails when u1 = u3 = MAX-U .
Perhaps not so significant for 32-bit systems as for 16-bit, it is
nevertheless an inconsistency which can catch a programmer
unawares.
Playing with the algorithm for WITHIN (A.6.2.2440) one gets:
: BETWEEN ( n1|u1 n2|u2 n3|u3 -- flag ) OVER - -ROT - U< 0= ;
It seems to work. If anyone finds a problem or knows something
better, let us know. In the meantime, here are several code versions.
code BETWEEN ( n1|u1 n2|u2 n3|u3 -- flag )
sub ebx, 0 [ebp]
mov ecx, 4 [ebp]
sub ecx, 0 [ebp]
cmp ebx, ecx
sbb ebx, ebx
not ebx
lea ebp, 8 [ebp]
ret
end-code
code BETWEEN ( n1|u1 n2|u2 n3|u3 -- flag )
bx pop ax pop cx pop
ax bx sub ax cx sub cx bx cmp
bx bx sbb bx not bx push next
end-code


|