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

[ColorForth] More newbie questions



On Fri, 28 Sep 2001, Leslie Snively wrote:

> 
> Thanks, Mark, this helps some, but not enough for my simple mind.  I've 
> been using Kris' list of commands and one of the things colorForth 
> doesn't seem to have many of are conditionals.  Since your description 
> of what "if" needs to behave correctly on the Pentium is the indirect 
> effect of a conditional, what's the mechanism for setting the flags?

Just about every operation (machine instruction) effects the flags in some
way. colorForth macros compile these machine instructions inside a
definition. A definition in colorForth consists of zero or more machine
instructions followed by a return instruction or a unconditional
jump. The Pentium manual is the best place to go to understand the
behavior of these instructions.

For our purposes it is only necessary to think of the top element of the
stack. If the result is zero, the zero flag will be set. For example, in
colorForth the following sequences should set the zero flag:

0
1 -1 +
f0 0f and
f0 0f ?
1 1 or
0 0 or
0 - -

Note that these are untested, also or is really xor and - is the ones
complement (logical not).
  
> (In the working code I'm developing I do an arithmetic operation 
> immediately before the "if", as you suggest, with the intent of 
> branching on a zero or not zero outcome.  But it appears not to effect 
> the zero flag so the "if" is not doing what I would expect.)  I expect 
> that there are other ways to accomplish this function in colorForth that 
> I'm not familiar with or not clever enough to have sorted out yet.  Any 
> hints are appreciated.

Could possibly be a mistake, maybe you could post the code. I'm strugling
myself with a macro which looks correct, however it doesn't do what I
expect.

> 
> Mark, could you expand on what the result is of "?" testing bits?  My 
> playing with it, and Kris' description on his site suggests that it does 
> an "and" but the result effects the value of the zero flag.  Is this the 
> preferred or recommended mechanism for growing our own conditionals?

Note that the 'if' is the conditional. There are many conditional
operators on the pentium, however 'if'(jz) and '-if'(jns) are the only one
exposed by Chuck. I wrote a '+if'(js) conditional, but it turned out I
no longer needed the definition that used.

'?' 'less' are just convienent ways of seting flags without discarding the
values. '?' is implemented on the pentium as a 'test' instruction which is
the logical and between two arguments, less is implemented as the 'cmp'
instruction which sets the flags equivelently to subtracting the top of
the stack from the next element.

Mark


------------------------

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