Page 1 of 1
How to do binary OR for gas/as?
Posted: Fri Apr 27, 2018 9:52 pm
by Miquel
Do you know how to do a CONSTANT binary OR for gnu as / gas ?, the asm compiler that comes with gcc, for a 68K target.
For example in the next statement:
Code: Select all
move.l #(0x93009400 | (((\size >> 1) & 0xFF) << 16) | (((\size >> 1) & 0xFF00) >> 8)), (%a0)
problems: ^ ^
the compiler uses '|' for a comment start symbol, then, in this compiler which symbol is for binary OR?
I looked into documentation but it doesn't list all operands.
Re: How to do binary OR for gas/as?
Posted: Sat Apr 28, 2018 7:27 am
by cero
File: as.info, Node: M68K-Chars, Prev: M68K-Branch, Up: M68K-opcodes
9.23.6.2 Special Characters
...........................
Line comments are introduced by the `|' character appearing anywhere on
a line, unless the `--bitwise-or' command line option has been
specified.
An asterisk (`*') as the first character on a line marks the start
of a line comment as well.
A hash character (`#') as the first character on a line also marks
the start of a line comment, but in this case it could also be a
logical line number directive (*note Comments::) or a preprocessor
control command (*note Preprocessing::). If the hash character appears
elsewhere on a line it is used to introduce an immediate value. (This
is for compatibility with Sun's assembler).
Multiple statements on the same line can appear if they are separated
by the `;' character.
Not sure about alternative OR operator, but that page is clear otherwise.
Re: How to do binary OR for gas/as?
Posted: Sat Apr 28, 2018 9:27 am
by Miquel
I tried --bitwise-or as a flag on the command line, at least at version 6.3.0 doesn't work.
Code: Select all
gcc.exe: error: unrecognized command line option '--bitwise-or'
Re: How to do binary OR for gas/as?
Posted: Sat Apr 28, 2018 4:59 pm
by cero
It's an option to as, not gcc. To pass assembler commands via gcc, use -Wa,--bitwise-or
Re: How to do binary OR for gas/as?
Posted: Sat Apr 28, 2018 9:08 pm
by Miquel
It works beautifully, thanks!
Re: How to do binary OR for gas/as?
Posted: Sun Apr 29, 2018 12:12 am
by Sik
Also in case somebody wonders what GAS would normally want without that setting: ! (it should still work even with the setting)
Apparently the oldest 68000 assemblers used ! for OR and GAS picked up its convention from that time. Ugh =/
Re: How to do binary OR for gas/as?
Posted: Mon Apr 30, 2018 7:20 am
by Miquel
It sounds really odd... then the question is: what symbol is for LOGICAL NOT ?
Re: How to do binary OR for gas/as?
Posted: Mon Apr 30, 2018 9:19 am
by Sik
From what I could gather, it doesn't seem to exist (although I recall that logical operators in expressions return 0 or 1, so you can just compare the resulting value). Binary NOT is ~ (that's a tilde, for those who have to cope with phpBB's default font being trash).
Re: How to do binary OR for gas/as?
Posted: Mon Apr 30, 2018 12:38 pm
by Miquel
My bad, in C symbol '!' stands for binary OR (although can be used without problems for logic OR).
You are saying that '~' means binary OR in this as syntax, while the character '~' in C means binary toggle (or xor with all 1's)... so another mismatch.... Then --bitwise-or is not an option but really necessary.
To not ask again what is binary toggle in as syntax: is there a web or some place to see all the syntax?
Re: How to do binary OR for gas/as?
Posted: Mon Apr 30, 2018 3:26 pm
by Chilly Willy
Re: How to do binary OR for gas/as?
Posted: Tue May 01, 2018 9:13 am
by Miquel
I did this program:
Code: Select all
move.l #(0b1010 ^ 0b1001),%d0
move.l #(0b1010 & 0b1001),%d0
move.l #(0b1010 | 0b1001),%d0
move.l #(0b1010 ! 0b1001),%d0
move.l #(! 0b1001),%d0
move.l #(0b1010 ~ 0b1001),%d0
move.l #(~ 0b1001),%d0
with "-Wa,--bitwise-or" options it compile to:
Code: Select all
moveq #$3, D0
moveq #$8, D0
moveq #$b, D0
moveq #$-2, D0
moveq #$0, D0
error
moveq #$-a, D0
without "-Wa,--bitwise-or" option does this:
Code: Select all
moveq #$3, D0
moveq #$8, D0
error
moveq #$-2, D0
moveq #$0, D0
error
moveq #$-a, D0
Conclusions:
Code: Select all
& AND
| OR with "-Wa,--bitwise-or"
^ XOR
~ NOT
! a OR (NOT b)
! also works as unary, but seems to always result to 0 (?!?)
(all operators are binary)
While in C differs in: