flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > (-1 xor CONST) != (CONST xor -1)

Author
Thread Post new topic Reply to topic
IronFelix



Joined: 09 Dec 2004
Posts: 141
Location: Russia, Murmansk region
IronFelix 12 Jan 2009, 14:47
Hi, all!
Please, tell me, is it a bug:
Code:
 dd -1 xor 3     
is FFFFFFFF in memory, but
Code:
 dd 3 xor -1     
is FFFFFFFC.
It seems to me that both must be 0xFFFFFFFC.
Thanks.

_________________
Flat Assembler is the best!
Post 12 Jan 2009, 14:47
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8357
Location: Kraków, Poland
Tomasz Grysztar 12 Jan 2009, 14:57
IronFelix wrote:
Please, tell me, is it a bug:
Code:
 dd -1 xor 3     
is FFFFFFFF in memory

This should be:
Code:
dd (-1) xor 3    

because what you wrote is the same as:
Code:
dd -(1 xor 3)    

Check out the operators precedence in manual.
Post 12 Jan 2009, 14:57
View user's profile Send private message Visit poster's website Reply with quote
IronFelix



Joined: 09 Dec 2004
Posts: 141
Location: Russia, Murmansk region
IronFelix 12 Jan 2009, 15:07
Thanks for so quick reply and sorry for wasting your time, Tomasz.
Post 12 Jan 2009, 15:07
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20430
Location: In your JS exploiting you and your system
revolution 12 Jan 2009, 15:16
IronFelix wrote:
Code:
 dd -1 xor 3     
is FFFFFFFF in memory
Tomasz Grysztar wrote:
because what you wrote is the same as:
Code:
dd -(1 xor 3)    
Isn't -(1 xor 3) ===> -(2) ===> 0xFFFFFFFE?
Post 12 Jan 2009, 15:16
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8357
Location: Kraków, Poland
Tomasz Grysztar 12 Jan 2009, 15:20
revolution wrote:
Isn't -(1 xor 3) ===> -(2) ===> 0xFFFFFFFE?

And this is how fasm assembles it. Perhaps IronFelix made a mistake there.
Post 12 Jan 2009, 15:20
View user's profile Send private message Visit poster's website Reply with quote
IronFelix



Joined: 09 Dec 2004
Posts: 141
Location: Russia, Murmansk region
IronFelix 12 Jan 2009, 15:46
Yes, it is my mistake, sorry for it too, please.
Post 12 Jan 2009, 15:46
View user's profile Send private message Reply with quote
IceStudent



Joined: 19 Dec 2003
Posts: 60
Location: Ukraine
IceStudent 03 Feb 2009, 22:00
Tomasz Grysztar wrote:
Check out the operators precedence

But it seems that XOR have higher priority than unary minus. But, by manual, it is not (minus have zero priority and XOR have 3rd).

Is it a bug or feature?

Another example:
1 - 1 xor 1 != 1 xor 1 - 1

But in other languages this expressions are equal (1 - 1 ^ 1 == 1 ^ 1 - 1)
Post 03 Feb 2009, 22:00
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8357
Location: Kraków, Poland
Tomasz Grysztar 03 Feb 2009, 22:23
IceStudent wrote:
But it seems that XOR have highest priority than unary minus. But, by manual, it is not (minus have zero priority and XOR have 3rd).

Yes, XOR has higher priority than any minus (unary or binary), and this is exactly what manual states. The higher "priority" value gives a higher priority to operator, therefore operator with this value higher is processed first.

IceStudent wrote:
Another example:
1 - 1 xor 1 != 1 xor 1 - 1

But in other languages this expressions are equal (1 - 1 ^ 1 == 1 ^ 1 - 1)

In some languages they may be equal, in some not. In fasm XOR is processed before substraction, as shown in the manual.
Post 03 Feb 2009, 22:23
View user's profile Send private message Visit poster's website Reply with quote
IceStudent



Joined: 19 Dec 2003
Posts: 60
Location: Ukraine
IceStudent 03 Feb 2009, 23:05
In the manual a higher priority haves largest value?
Post 03 Feb 2009, 23:05
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20430
Location: In your JS exploiting you and your system
revolution 04 Feb 2009, 00:53
IceStudent wrote:
In the manual a higher priority haves largest value?
Just look at + and * priority. That will tell you whether you are going up or down in priority.
Post 04 Feb 2009, 00:53
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.