flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > Strangeness with xor operator in constants expression

Author
Thread Post new topic Reply to topic
bazizmix



Joined: 15 Jan 2016
Posts: 51
bazizmix 04 Feb 2018, 12:30
flat assembler version 1.72
Simple text:
Code:
ZZZ equ 1
mov eax,-1 xor ZZZ
mov eax,ZZZ xor -1    

and produced code:
Code:
B8 00 00 00 00 | mov eax,0         <-- wrong
B8 FE FF FF FF | mov eax,FFFFFFFE  <-- right    

But!!!
Code:
ZZZ equ 2
mov eax,-1 xor ZZZ
mov eax,ZZZ xor -1    

all OK:
Code:
B8 FD FF FF F | mov eax,FFFFFFFD
B8 FD FF FF F | mov eax,FFFFFFFD     
Post 04 Feb 2018, 12:30
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 19873
Location: In your JS exploiting you and your system
revolution 04 Feb 2018, 13:03
Unary minus has a lower precedence than xor. You can put brackets around the leading minus to force what you need.
Code:
mov eax,(-1) xor ZZZ    


Last edited by revolution on 04 Feb 2018, 13:48; edited 1 time in total
Post 04 Feb 2018, 13:03
View user's profile Send private message Visit poster's website Reply with quote
bazizmix



Joined: 15 Jan 2016
Posts: 51
bazizmix 04 Feb 2018, 13:27
Thanks, revolution!
Post 04 Feb 2018, 13:27
View user's profile Send private message 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-2023, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.