GAS bad error message (was: Braindead AT&T Syntax)

All off topic discussions go here. Everything from the funny thing your cat did to your favorite tv shows. Non-programming computer questions are ok too.
evoex
Member
Member
Posts: 103
Joined: Tue Dec 13, 2011 4:11 pm

GAS bad error message (was: Braindead AT&T Syntax)

Post by evoex »

Damn it... I just spend half an hour trying to fix an assembler error "operand size mismatch" on the following line:

Code: Select all

testq 0x18(%rsp), $3
Tried to play around with operand sizes, tried to find out if perhaps this instruction didn't work for 64 bit operands... Nope. Just forgot for a moment that the order of the instruction is reversed, and apparently the best error message for this was "operand size mismatch".
Because reversing the order is logical right? Having the destination on the right? Even if there isn't a destination.

I'm not sure why I decided to use AT&T syntax for my OS. It must've been some extreme form of masochism.

What are your thoughts on AT&T syntax? To be fair, I grew up with Intel syntax, so perhaps it's just a matter of getting used to it. But I just find Intel easier to read, write, and just not braindead.

Just had to rant about this somewhat ;-).
Last edited by evoex on Fri Aug 28, 2015 12:45 pm, edited 1 time in total.
onlyonemac
Member
Member
Posts: 1146
Joined: Sat Mar 01, 2014 2:59 pm

Re: Braindead AT&T Syntax

Post by onlyonemac »

I hate AT&T syntax. Intel syntax is logical - having the destination on the left is consistent with higher-level languages like C, and more consistent with mathematical notation as well. Whoever thought of the idea of putting the destination on the right must have been mad.
When you start writing an OS you do the minimum possible to get the x86 processor in a usable state, then you try to get as far away from it as possible.

Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
User avatar
Roman
Member
Member
Posts: 568
Joined: Thu Mar 27, 2014 3:57 am
Location: Moscow, Russia
Contact:

Re: Braindead AT&T Syntax

Post by Roman »

I'm convenient with both styles. But I agree that the Intel syntax is better.
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
User avatar
Artlav
Member
Member
Posts: 178
Joined: Fri Aug 21, 2009 5:54 am
Location: Moscow, Russia
Contact:

Re: Braindead AT&T Syntax

Post by Artlav »

Might be an example of human-orientedness.
We say take it from ax to bx, not put into bx the content of ax.
So there comes the destination on the right.

Similar thing with endianness - it makes sense for a machine to have the bytes in sequence that it would need them, but humans are used to reading numbers backwards.
So, some processors were made with bytes reversed.

And we have encountered, got confused and got used to the machine representation so long ago that we don't really remember being confused.

Unless it permanently damaged our brain's ability to do simple offset math, because people speak from one to n, and arrays are indexed from 0 to n-1, and the newly developed mathematical subsystem of a child got fried from this revelation...
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Braindead AT&T Syntax

Post by iansjack »

I think of a move instruction as (for example):

"I want to move the contents of the register bx to the register ax"

hence:

mov %bx, %ax

Makes perfect sense to me, and sounds more natural than:

"I want to move into register ax the contents of register bx"

But it's just syntax, so no big deal either way; takes about 5 minutes to learn it. Neither of them is "wrong".
alexfru
Member
Member
Posts: 1111
Joined: Tue Mar 04, 2014 5:27 am

Re: Braindead AT&T Syntax

Post by alexfru »

iansjack wrote: mov %bx, %ax

Makes perfect sense to me
When you look at it through the prism of mathematics and higher level programming languages like Basic, C/C++ (and derivatives), Pascal and others

ax = bx
let ax = bx
ax = bx;
ax := bx;
etc

all make perfect sense as well. And it fits just fine into other linguistic possibilities like "I gave him the book" or "Le di el libro".
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Braindead AT&T Syntax

Post by iansjack »

I think a more accurate comparison (in C) would be a function call rather than an assignment expression using an infix operator. But I have to admit that in the C Standard Library we have:

strcpy(dest, source)

which I have always felt was rather illogical.

As for the English example you give, I think a closer comparison would be "I put the book into the library" (or, in your preferred notation, "I put into the library the book"). I guess you could express the move instruction as "Move register ax bx", but it's not a natural way of speaking.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Braindead AT&T Syntax

Post by Combuster »

Nice comparison with English, when it is inconsistent to say the least. They can't even rely on just a verb without messing with the preposition as well:

Code: Select all

b += a; // add a to b
b -= a; // subtract a from b
a *= b; // multiply a with b
a /= b; // divide a by b
Left-destination assignments are not hard to find either: "Let X equal Y" or "assume X is Y" or #"define X to be Y"
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
onlyonemac
Member
Member
Posts: 1146
Joined: Sat Mar 01, 2014 2:59 pm

Re: Braindead AT&T Syntax

Post by onlyonemac »

iansjack wrote:I think a more accurate comparison (in C) would be a function call rather than an assignment expression using an infix operator. But I have to admit that in the C Standard Library we have:

strcpy(dest, source)

which I have always felt was rather illogical.
Again I have always thought that that is logical, following on from the built-in assignment operators.

Code: Select all

a = b;
a += b;
Thus

Code: Select all

function_move(a, b);
function_add(a, b);
Thus

Code: Select all

mov ax, bx
add ax, bx
When you start writing an OS you do the minimum possible to get the x86 processor in a usable state, then you try to get as far away from it as possible.

Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
User avatar
Rusky
Member
Member
Posts: 792
Joined: Wed Jan 06, 2010 7:07 pm

Re: Braindead AT&T Syntax

Post by Rusky »

One nice thing about putting the destination on the left, in higher level languages, is that it is often a new name being defined, and the source is often a much more complicated expression. Neither of these apply in assembly, where it's honestly completely arbitrary and doesn't matter.

The real problem with AT&T syntax is not operand ordering, which you can figure out in five minutes, but address calculation syntax and literals vs dereferencing. Intel syntax handles that side of things much more clearly.
kzinti
Member
Member
Posts: 898
Joined: Mon Feb 02, 2015 7:11 pm

Re: Braindead AT&T Syntax

Post by kzinti »

Rusky wrote:The real problem with AT&T syntax is not operand ordering, which you can figure out in five minutes, but address calculation syntax and literals vs dereferencing. Intel syntax handles that side of things much more clearly.
I fully agree. In fact, the Intel operand ordering is the oddity. Most (all) other architectures use assemblers that follow the AT&T operand order.


From http://simon.baymoo.org/universe/tools/ ... symset.txt:
Other differences aside, you will notice that the AT&T format makes assignments
from left to right, and that modifying instructions modify their right-most
arguments. The primary reason for this difference is due to the VAX assembly
format for which the AT&T style was originally invented. (The Motorola 68000
and its descendents were heavily influenced by the VAX. Likewise, their
assembly language format moves in this direction as well!)
User avatar
Roman
Member
Member
Posts: 568
Joined: Thu Mar 27, 2014 3:57 am
Location: Moscow, Russia
Contact:

Re: Braindead AT&T Syntax

Post by Roman »

I think, that the Intel syntax is better because:
  • In mathematics and high level programming languages you write: "x = y", thus "insn dst, src" is more straightforward for a programmer.
  • No need for postfixes like 'q', 'l', 'w' and 'b' in most cases.
  • No prefixes like % and $.
  • Indexed load syntax is clearer.
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
kzinti
Member
Member
Posts: 898
Joined: Mon Feb 02, 2015 7:11 pm

Re: Braindead AT&T Syntax

Post by kzinti »

Some proponents of AT&T syntax will point out that having suffixes on mnemonics is a good thing. They are providing you with static type checking, ensuring your operands are of the right size and that the instructions generated are exactly the ones you wanted. Same with the $ and % prefixes. The syntax can help you catch errors.

If only I could get Intel ordering and addressing with the AT&T prefixes/suffixes, I'd be very happy indeed.
onlyonemac
Member
Member
Posts: 1146
Joined: Sat Mar 01, 2014 2:59 pm

Re: Braindead AT&T Syntax

Post by onlyonemac »

Rusky wrote:The real problem with AT&T syntax is not operand ordering, which you can figure out in five minutes, but address calculation syntax and literals vs dereferencing. Intel syntax handles that side of things much more clearly.
I am not so familiar with that side of things; I have avoided AT&T syntax since I went mad trying to understand it - when I write code, I want the code to be as intuitive as possible so that I can use my brain power on more important issues than trying to interpret the code, therefore I use Intel syntax.
When you start writing an OS you do the minimum possible to get the x86 processor in a usable state, then you try to get as far away from it as possible.

Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
Octocontrabass
Member
Member
Posts: 5572
Joined: Mon Mar 25, 2013 7:01 pm

Re: Braindead AT&T Syntax

Post by Octocontrabass »

kiznit wrote:Some proponents of AT&T syntax will point out that having suffixes on mnemonics is a good thing. They are providing you with static type checking, ensuring your operands are of the right size and that the instructions generated are exactly the ones you wanted.
Registers already have inherent size attributes, which makes the suffixes redundant most of the time. AT&T syntax doesn't stop a programmer from mistakenly moving a variable into a register of the wrong size; the programmer will simply choose the suffix that matches the register size.

Intel syntax uses keywords on the operands instead of suffixes on the instruction, and to me this makes more sense: the size of a variable is a property of that variable. For those (usually rare) cases where the two operands have different sizes, it's immediately obvious which operand is which size, as well.
kiznit wrote:Same with the $ and % prefixes. The syntax can help you catch errors.
For the $ prefix, you have to specify which specific flavor of Intel syntax you're comparing against. The difference between immediate and memory operands isn't obvious in MASM syntax, but NASM syntax always requires square brackets around memory operands.

For the % prefix, using symbols that have the same names as CPU registers is asking for trouble anyway. For Intel syntax, it's a namespace collision, and you might choose a similar name. In either syntax, your symbol and the register are only one small typo away from each other.
Post Reply