0

I am using GNU as on an x86 machine.

I know that LEA only works as lea <mem>, <reg32> in AT&T syntax, with a register destination and a memory addressing mode as the source. lea 100(%eax), %eax assembles fine, for example.

But why does GAS call it a size mismatch in its error message when you reverse the operands, instead of some kind of syntax error?

lea %eax, 100(%eax)

When I assmble that, I am getting operand size mismatch for `lea'.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • 1
    I suppose this is just a quirk of how the assembler checks if the instruction matches a known form. – fuz Jan 12 '20 at 17:36
  • 1
    GAS doesn't have as nice error messages as NASM / YASM. Stuff like this is not rare in GAS. For people that know asm for the target platform, it's only a minor inconvenience; you can generally just look at the instruction, smack yourself in the forehead, and realize what's wrong with the operands. It's not helpful for beginners, though. – Peter Cordes Jan 12 '20 at 19:02
  • Hey @PeterCordes , can you also see this https://stackoverflow.com/questions/59707176/what-is-difference-between-jmp-and-jmpw-in-att-syntax-gnu-assembler. Is it also related to faulty error messaging ? – Aditya Singh Rathore Jan 12 '20 at 19:05
  • 1
    No, it's real; see the footnote in [an answer I wrote a couple years ago](https://stackoverflow.com/questions/50341094/gas-assembler-not-using-2-byte-relative-jmp-displacement-encoding-only-1-byte-o/50341926#50341926): GAS seems to think the `jmpw` mnemonic is only for indirect jumps. Therefore it interprets the `0x100` operand as an absolute memory address, like `jmpw *0x100` with a word operand-size load from memory, truncating EIP to 16-bit IP. Yes, it's basically a dup of [what is jmpl instruction in x86?](//stackoverflow.com/q/54386736) – Peter Cordes Jan 12 '20 at 19:19
  • @PeterCordes Thanks man. I really appreciate the answer. – Aditya Singh Rathore Jan 12 '20 at 19:21

1 Answers1

1

Technically, a syntax error would mean that the text cannot be recognized and parsed according to given the grammar they are using.

The size error appears to be post parsing.

Generally speaking, syntax errors (errors in parsing/recognizing) offer a worse user experience than semantic errors (post parsing).

When parsing fails the rest of the text is in doubt (though in assembly, restarting the parse could be simple as discard the line and going on to the next line).  When parsing fails, we also don't know a lot about the actual error.

Given a choice between restricting something by way of the grammar, vs. restricting something by a semantic check, the latter is usually preferred as it (both allows the parse to continue, and then) offers an opportunity for better error messages.

In this particular case, the error message does leave a lot to be desired — so it is probably a general error message used in many places.

Erik Eidt
  • 23,049
  • 2
  • 29
  • 53