How to do binary OR for gas/as?

Ask anything your want about Megadrive/Genesis programming.

Moderator: BigEvilCorporation

Post Reply
User avatar
Miquel
Very interested
Posts: 344
Joined: Sat Jul 30, 2016 12:33 am

How to do binary OR for gas/as?

Post by Miquel » Fri Apr 27, 2018 9:52 pm

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.

cero
Very interested
Posts: 230
Joined: Mon Nov 30, 2015 1:55 pm

Re: How to do binary OR for gas/as?

Post by cero » Sat Apr 28, 2018 7:27 am

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.

User avatar
Miquel
Very interested
Posts: 344
Joined: Sat Jul 30, 2016 12:33 am

Re: How to do binary OR for gas/as?

Post by Miquel » Sat Apr 28, 2018 9:27 am

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'

cero
Very interested
Posts: 230
Joined: Mon Nov 30, 2015 1:55 pm

Re: How to do binary OR for gas/as?

Post by cero » Sat Apr 28, 2018 4:59 pm

It's an option to as, not gcc. To pass assembler commands via gcc, use -Wa,--bitwise-or

User avatar
Miquel
Very interested
Posts: 344
Joined: Sat Jul 30, 2016 12:33 am

Re: How to do binary OR for gas/as?

Post by Miquel » Sat Apr 28, 2018 9:08 pm

It works beautifully, thanks!

User avatar
Sik
Very interested
Posts: 719
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: How to do binary OR for gas/as?

Post by Sik » Sun Apr 29, 2018 12:12 am

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 =/
Sik is pronounced as "seek", not as "sick".

User avatar
Miquel
Very interested
Posts: 344
Joined: Sat Jul 30, 2016 12:33 am

Re: How to do binary OR for gas/as?

Post by Miquel » Mon Apr 30, 2018 7:20 am

It sounds really odd... then the question is: what symbol is for LOGICAL NOT ?

User avatar
Sik
Very interested
Posts: 719
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: How to do binary OR for gas/as?

Post by Sik » Mon Apr 30, 2018 9:19 am

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).
Sik is pronounced as "seek", not as "sick".

User avatar
Miquel
Very interested
Posts: 344
Joined: Sat Jul 30, 2016 12:33 am

Re: How to do binary OR for gas/as?

Post by Miquel » Mon Apr 30, 2018 12:38 pm

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?
Last edited by Miquel on Tue May 01, 2018 2:02 am, edited 2 times in total.

Chilly Willy
Very interested
Posts: 2609
Joined: Fri Aug 17, 2007 9:33 pm

Re: How to do binary OR for gas/as?

Post by Chilly Willy » Mon Apr 30, 2018 3:26 pm

Unless otherwise specified for a platform, the standard gas syntax is as follows:

https://sourceware.org/binutils/docs/as ... Prefix-Ops
https://sourceware.org/binutils/docs/as ... #Infix-Ops

User avatar
Miquel
Very interested
Posts: 344
Joined: Sat Jul 30, 2016 12:33 am

Re: How to do binary OR for gas/as?

Post by Miquel » Tue May 01, 2018 9:13 am

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:

Code: Select all

!      logical NOT

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest