home .. forth .. colorforth mail list archive ..

[ColorForth] Question regarding if


(As I found out last time I tried to be helpful on this list... :-)

The '?' word is a macro that expects to be preceded by a literal value
during compilation, and which compiles the x86 TEST instruction of that
literal with whatever's on the top of the stack at runtime. The TEST
instruction AND's the bits of its operands, and sets the processor flags
accordingly, but doesn't actually change either of it's operands.

So, something like "4 ? if foo then" will skip foo unless AND'ing 4 with
the top of stack would have been non-zero.

I hope that makes sense, and that I got it right this time. :-)

On Fri, 12 Jul 2002, Kristopher Johnson wrote:

> The ? (question-mark) word will test the top-of-stack and set CPU flags.
> 
> So you may be able to write your word like
> 
> : tst ? if 1 ; then 2 ;
> 
> (I can't test this myself.)
> 
> -- Kris
> 
> 
> --- Alex Thiel <alex.lists@xxxxxxxxxx> wrote:
> > Hello,
> > 
> > I want to write a word that test the TOS for a non-zero value. I have tried
> > 
> > : tst if 1 ; then 2 ;
> > : foo 0 tst 1 tst ;
> > 
> > Execution of foo leaves 0 2 1 2 on the stack, i.e. pushing a constant does
> > not 
> > seem to affect the flags. Is this expected behavior?
> > 
> > As a workaround I do
> > : tst 0 or if 1 ; then 2 ;
> > 
> > Does anyone have a better idea?
> > 
> > Cheers,
> > 
> > 	Alex
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Sign up for SBC Yahoo! Dial - First Month Free
> http://sbc.yahoo.com
> ------------------------
> 
> To Unsubscribe from this list, send mail to Mdaemon@xxxxxxxxxxxxxxxxxx with:
> unsubscribe ColorForth
> as the first and only line within the message body
> Problems   -   List-Admin@xxxxxxxxxxxxxxxxxx
> Main ColorForth site   -   http://www.colorforth.com
> Wiki page http://kristopherjohnson.net/wiki/ColorForth
> ColorForth index http://www.users.qwest.net/~loveall/c4index.htm
> 
> 
> 
------------------------

To Unsubscribe from this list, send mail to Mdaemon@xxxxxxxxxxxxxxxxxx with:
unsubscribe ColorForth
as the first and only line within the message body
Problems   -   List-Admin@xxxxxxxxxxxxxxxxxx
Main ColorForth site   -   http://www.colorforth.com
Wiki page http://kristopherjohnson.net/wiki/ColorForth
ColorForth index http://www.users.qwest.net/~loveall/c4index.htm