flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Can I assign result of condition?

Author
Thread Post new topic Reply to topic
Jin X



Joined: 06 Mar 2004
Posts: 66
Location: Russia
Jin X
Can I realize something like
Code:
a = (b <> 0)    

another way than:
Code:
if b
  a = 1
else
  a = 0
end if    

???

More compact.
Post 14 Oct 2019, 12:14
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7572
Location: Kraków, Poland
Tomasz Grysztar
No, there is no such thing in fasm's language as assignable result of a condition. Logical expressions can only be used with a command like IF or WHILE. In fasm's semantics "true"/"false" are not really numeric values at all.
Post 14 Oct 2019, 12:29
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17010
Location: In your JS exploiting you and your system
revolution
The equals (=) character serves both as an operator and an assignment.

So this code would be ambiguous:
Code:
if a = b ;logical comparison or numeric assignment?    


I think if you wanted to allow logical conditions to generate a numeric value then you might want to introduce a separate operator. C uses == for comparison, and = for assignment. And you have probably seen how much confusion that has caused over the years. Especially since C also implicitly evaluates assignments.
Post 14 Oct 2019, 15:04
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7572
Location: Kraków, Poland
Tomasz Grysztar
revolution wrote:
I think if you wanted to allow logical conditions to generate a numeric value then you might want to introduce a separate operator. C uses == for comparison, and = for assignment. And you have probably seen how much confusion that has caused over the years. Especially since C also implicitly evaluates assignments.
Yes, this might be an underlying justification. The design of fasm's syntax borrows from old languages like Fortran or Basic that had contextual meaning of "=".
Post 14 Oct 2019, 15:09
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17010
Location: In your JS exploiting you and your system
revolution
This might work:
Code:
a ← (b <> c)    
But typing the ← character is tricky.

Also use a binary operator to coerce logical to numeric conversion:
Code:
if a * (b <> c) > d ;use a binary operator to coerce logical to numeric conversion    
Post 14 Oct 2019, 15:28
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-2020, Tomasz Grysztar.

Powered by rwasa.