Skip to content

0= need not be a primitive #8

@garysnyder

Description

@garysnyder

We can derive 0= very early in a .f file.

Sweeping all the 1s in a number up ( dup 2* or ), repeatedly, sets bit 15 if non zero.

Since we can look at the stack, at any byte, half way between two 16 bit words, we can swap the upper and lower bytes. This moves bit 15 to bit 7 and bit 8 to bit 0. ( dup sp@ 1 + @ swap drop swap drop )

Shifting the result left by one ( 2* ) moves the original bit 15 to bit 8. Swapping again moves it to bit 0.
Mask only bit 0, invert and add 1 to make it a flag for 0<>
( 1 and invert 1 + )
invert again if you want 0=

It's much slower than a primitive, but saves a little .asm space.

Does that make 6 ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions