## Stack effect is inverted - what does that mean?

If you want to discuss about Oforth...

### Stack effect is inverted - what does that mean?

In the documentation for bitLeft and bitRight, a precaution mentioning to be careful due to Oforth's stack effect to invert an integer (method of
integer). If I understand the precaution correctly, would that mean that the maximum positive number on the stack if incremented by 1 will result in a negative number?

If that's so, then bit shifting has to have the result checked for whether the most significant bit has been toggled from 0 to 1 then, right?

Is there a way to verify the maximum number of bits a particular processor is capable of handling?

Thanks in advance,

Bob
bobgillies

Posts: 60
Joined: 24 Jan 2017 06:26

### Re: Stack effect is inverted - what does that mean?

Hello,

Sorry for the late answer.

No, this is not related to negative results, this is only related to the order of the 2 objects on the stack (the number to shift and the number of shift to do).

#bitLeft and #bitRight are methods of the Integer class.
The top of the stack is the integer we want to shift, not the number of shift to do.
So #bitLeft (and #bitRight) stack effects is :

bitLeft \ n x1 -- x2 : Logical shift of n bits on x1 giving x2

You can write :
Code: Select all
`0x000000111111 bitLeft( 24 )24 0x000000111111 bitLeft0xFFFFFF111111 bitRight( 24 )24 0xFFFFFF111111 bitRight`

There is a warning into the documentation because this is not the way the classical Forth words LSHIFT and RSHIFT work :

LSHIFT \ x1 n -- x2 : Logical shift of n bits on x1 giving x2.

This is not the same order in Oforth.

Franck
Franck

Posts: 155
Joined: 29 Oct 2014 19:01

Return to Discussions

### Who is online

Users browsing this forum: No registered users and 1 guest