flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > Logical xor operator for Fasm needed? With "^" cha

Goto page 1, 2  Next

Should a logical xor operator be added to Fasm? "^"
yes
55%
 55%  [ 15 ]
no need, thanks
11%
 11%  [ 3 ]
no, this would anticipate with Fasms concepts
0%
 0%  [ 0 ]
let Privalov decide it alone
25%
 25%  [ 7 ]
don't know
3%
 3%  [ 1 ]
something else
3%
 3%  [ 1 ]
Total Votes : 27

Author
Thread Post new topic Reply to topic
MCD



Joined: 21 Aug 2004
Posts: 602
Location: Germany
MCD 23 Dec 2004, 16:06
I have some sources that would be somewhat easier and more readable if Fasm
had a logical xor operator (like the "|" or "&", but with xor). Sure, xor can
be rewritten to a longer combination of "|", "&" and "~", but even the
shortest form I know is still longy (I suppose everyone here knows it ;] ):

let a,b be some boolean values
a xor b = (a or b) and not(a and b)

Imagine this with more complicated logical values for a and b, say some
comparisions (a = 0), then this would give something quiet hard to read:

Code:
;Assume the following:
; a: XPos > 200
; b: YPos < 100

;Then this...
if ((XPos > 200) | (YPos < 100)) & ~((XPos > 200) & (YPos < 100))
; ... some kind of code
end if

;...could be abreviated to this
if (XPos > 200) ^ (YPos < 100)
; ... some kind of code
end if
    


The problem with xor is, that it cannot be done with macros or equates as
easy as I did it with the numerical sar operator some time ago.

So, I thought to myself, why not add a logical xor operator? And so I did.
I chose the "^" character for it, I guess that this fits best with already
existing Fasm C-based operators.

Don't worry about stuff like "It will bloat Fasm!", it only takes up
additional 27 bytes. The only question now is if it will be used enough to be
worth being implemented into Fasm. So, please take part at this poll.

_________________
MCD - the inevitable return of the Mad Computer Doggy

-||__/
.|+-~
.|| ||
Post 23 Dec 2004, 16:06
View user's profile Send private message Reply with quote
MCD



Joined: 21 Aug 2004
Posts: 602
Location: Germany
MCD 23 Dec 2004, 16:10
HERE IS A STEP-BY-STEP IMPLEMENTATION INSTRUCTION

"PREPROCE.INC":
---------------

At the very end
Old:
----
Code:
symbol_characters db 27
 db 9,0Ah,0Dh,1Ah,' +-/*:=|&~()[]<>{},;\#`'
    

New:
----
Code:
symbol_characters db 28
 db 9,0Ah,0Dh,1Ah,' +-/*:=|&^~()[]<>{},;\#`'
    



"EXPRESSI.INC":
---------------

At calculate_logical_expression
Old:
----
Code:
logical_loop:
 push    eax
 lods    byte [esi]
  cmp     al,'|'
    je      logical_or
  cmp     al,'&'
        je      logical_and
    

New:
----
Code:
logical_loop:
     push    eax
 lods    byte [esi]
  cmp     al,'|'
    je      logical_or
  cmp     al,'&'
        je      logical_and
 cmp     al,'^'
    je      logical_xor
    



Just a few lines below
Old:
----
Code:
logical_and:
    call    get_logical_value
   pop     ebx
 and     al,bl
       jmp     logical_loop
get_logical_value:
    

New:
----
Code:
logical_and:
   call    get_logical_value
   pop     ebx
 and     al,bl
       jmp     logical_loop
    logical_xor:
        call    get_logical_value
   pop     ebx
 xor     al,bl
       jmp     logical_loop
get_logical_value:
    



At get_logical_value
Old:
----
Code:
    check_character:
;       ...     ~7 lines
       cmp     al,'|'
    je      stop
        cmp     al,'&'
        je      stop
    

New:
----
Code:
    check_character:
;       ...     ~7 lines
 cmp     al,'|'
    je      stop
        cmp     al,'&'
        je      stop
        cmp     al,'^'
    je      stop
    



"PARSER.INC":
-------------

Old:
----
Code:
parse_arguments:
;       ...     ~7 lines
     cmp     al,'|'
    je      separator
   cmp     al,'&'
        je      separator
    

New:
----
Code:
parse_arguments:
;       ...     ~7 lines
        cmp     al,'|'
    je      separator
   cmp     al,'&'
        je      separator
   cmp     al,'^'
    je      separator
    

_________________
MCD - the inevitable return of the Mad Computer Doggy

-||__/
.|+-~
.|| ||
Post 23 Dec 2004, 16:10
View user's profile Send private message Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1166
Location: Overflow
Matrix 24 Dec 2004, 00:11
hy mcd
it seems to me you are beginning to make things more comfortable Smile

do i see it right?
Post 24 Dec 2004, 00:11
View user's profile Send private message Visit poster's website Reply with quote
MCD



Joined: 21 Aug 2004
Posts: 602
Location: Germany
MCD 25 Dec 2004, 18:52
Perhaps. Explain, what do you mean with "more comfortable"?

If it means what I think now, than you should admit that from the "|" OR and "&" AND operator, 1 is superfluous because of the law of De Morgan:

lets assume a and b or 2 boolean values, than this...
Code:
if a & b
;... some code
end if

if a | b
;... some other code
end if
    


could be written as
Code:
if a & b
;... some code
end if

if ~(~a & ~b)
;... some other code
end if
    


This means that you can sacrify either the AND or OR operator, but not both. E.g. you can rewrite any combination of ORs and ANDs to just ANDs or Ors.

Even the XOR:
Code:
if a ^ b;lets assume it already exists Wink
;... some code
end if
    


with just the AND and NEGATION operators
Code:
if ~(~a & ~b) & ~(a & b)
end if
    
Post 25 Dec 2004, 18:52
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2139
Location: Estonia
Madis731 28 Dec 2004, 20:22
I answered yes, but I've got something to add. I want "xor" not some character ("^"), because everything else is clearly written out like this:
((data1 shr 4) + (data1 shl 4)) and 0FFFFFFFFh
I've already gotten used to it - that is why I hope BOTH can be implemented.
Sure, (data1>>4+data1<<4)&(-1) would be short and clean, but again we might want to think about big project made with FASM.
Post 28 Dec 2004, 20:22
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
MCD



Joined: 21 Aug 2004
Posts: 602
Location: Germany
MCD 28 Dec 2004, 20:31
Perhaps I'm wrong, but I meant only the LOGICAL xor operator (see "|" and "&") used for "IF" blocks, not the numerical xor which is already implemented, eg
Code:
db 1 xor 5    

already works, but whereas
Code:
if (Somevalue < 5) ^ (Someothervalue = 0)
; some code
end if
    

does not.

Also, I think that it would be difficult in implementing a logical xor operator with an outwritten "xor", since Fasm already uses this as a numerical one.

_________________
MCD - the inevitable return of the Mad Computer Doggy

-||__/
.|+-~
.|| ||
Post 28 Dec 2004, 20:31
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 28 Dec 2004, 21:04
i think both numerical "xor" and logical "^" should be added.
Post 28 Dec 2004, 21:04
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
MCD



Joined: 21 Aug 2004
Posts: 602
Location: Germany
MCD 28 Dec 2004, 21:07
numerical "xor" already exists
Post 28 Dec 2004, 21:07
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 29 Dec 2004, 14:39
Embarassed
Post 29 Dec 2004, 14:39
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
comrade



Joined: 16 Jun 2003
Posts: 1150
Location: Russian Federation
comrade 30 Dec 2004, 05:02
Perhaps Privalov can also add bswap which he already implemented, and perhaps rol and ror as well Laughing
Post 30 Dec 2004, 05:02
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1166
Location: Overflow
Matrix 30 Dec 2004, 05:42
what do you think adding "^ equ xor"
? Smile
Code:
    
Post 30 Dec 2004, 05:42
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 01 Jan 2005, 23:51
shit.
Saving two chars per instruction isn't worth of losing readiability (or forcing reader to learn all your such substitutions)
Post 01 Jan 2005, 23:51
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1166
Location: Overflow
Matrix 02 Jan 2005, 01:28
yeah, you're right, i have no problems with xor,
C has these kind of short forms ^ !
but it was probably not meant to be used like ^ ax,bx
assembly mnemonics were developed so the programmers can easily learn the opcodes mov, add, sub, mul seems pretty easy to learn, not like some symbols ( apart from + - * / )
Post 02 Jan 2005, 01:28
View user's profile Send private message Visit poster's website Reply with quote
MCD



Joined: 21 Aug 2004
Posts: 602
Location: Germany
MCD 05 Jan 2005, 19:04
Matrix posted:
Quote:
yeah, you're right, i have no problems with xor,
C has these kind of short forms ^ !
but it was probably not meant to be used like ^ ax,bx
assembly mnemonics were developed so the programmers can easily learn the opcodes mov, add, sub, mul seems pretty easy to learn, not like some symbols ( apart from + - * / )

vid posted:
Quote:

shit.
Saving two chars per instruction isn't worth of losing readiability (or forcing reader to learn all your such substitutions)


I fully agree with you, Matrix and vid in term of assembly instructions. I mean that this "^" should only be implemented for Fasm's logical/boolean stuff, so that both the numerical constant "xor" and assembly instruction "xor" will remain as they are.

Quote:

Perhaps Privalov can also add bswap which he already implemented, and perhaps rol and ror as well

if anyone is interested in additional operators for Fasm, take a look at this post of mine. (also in flat assembler > Compiler Internals)
http://board.flatassembler.net/topic.php?t=2679

_________________
MCD - the inevitable return of the Mad Computer Doggy

-||__/
.|+-~
.|| ||
Post 05 Jan 2005, 19:04
View user's profile Send private message Reply with quote
MCD



Joined: 21 Aug 2004
Posts: 602
Location: Germany
MCD 11 Jan 2005, 10:49
Just another thing:

Privalov, from all those stuff I proposed to add into Fasm, there is 1 feature I miss the most:

I need a size detecting operator Crying or Very sad (I have already asked you about it several months ago), something like sizeof
Code:
macro MovAcc Var
{
 if sizeof Var = 1
  mov al,[Var]
 else if sizeof Var = 2
  mov ax,[Var]
 else if sizeof Var = 4
  mov eax,[Var]
 end if
}
;I know, this is a bad example
    

_________________
MCD - the inevitable return of the Mad Computer Doggy

-||__/
.|+-~
.|| ||
Post 11 Jan 2005, 10:49
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 17 Jan 2005, 14:37
well, i think this might work, but there will have to be several cases:

sizeof label - size assigned to label. But what will sizeof do when label doesn't have assigned size,
i suppose error message
sizeof general purpose register - should work okay
sizeof segment register - 16bits?
sizeof size operator - size as number (in bytes)
sizeof anything else - just like sizeof label with unassigned size, throw error.

as i think of it, it may work.
Post 17 Jan 2005, 14:37
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 29 Aug 2007, 21:09
(Don't ask how is possible that I reached to this thread)

Why logical (non-numerical) xor was not implemented after all?
Post 29 Aug 2007, 21:09
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 30 Aug 2007, 10:46
loco: probably because it is so seldom needed?
Post 30 Aug 2007, 10:46
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 30 Aug 2007, 16:47
I suppose, but for the sake of completeness perhaps it should be included anyway?

Though, thinking about it better, is there a language that supports it (again, logical, not numerical)?
Post 30 Aug 2007, 16:47
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 30 Aug 2007, 21:25
loco: you know, it is always possible to do with higher level constructs...

Code:
if (c1) ^ (c2)
...
if c1
  x1 = 1
else 
  x1 = 0
end if
if c2
  x2 = 1
else
  x2 = 0
end if
if (x1 & !x2) | (!x1 & x2)
    


yes, i agree this is lack of completness, but FASM never tried to be complete. It was designed to be clean and compact, and for that it does its job greatly
Post 30 Aug 2007, 21:25
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.