1

I've been writing a programming game -- and with that comes writing a programming language. Initially I wanted the programming language to be a gross simplification of assembly language (like the game EXAPUNKS if anybody knows what that is).

But as things went on, I got pretty feature addicted and the language ended up pretty much exactly like a slightly simplified x86 with intel syntax. With one key distinction:

My language doesn't require commas. mov [eax+1] ebx is perfectly valid in my game.

So, why are commas needed in the intel syntax? Is there some case where a lack of commas would cause ambiguity? I am considering implementing commas just to make the language more familiar but it doesn't really need them.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Thor Correia
  • 1,159
  • 1
  • 12
  • 20
  • Some people like to leave space between operators, e.g. `[eax + 1]` for readability. You can probably still parse that, though. – Jester May 30 '20 at 11:34
  • 6
    In Intel syntax, you can write `eax[ebx]` for a memory operand. Without commas, this is ambiguous. – fuz May 30 '20 at 12:29
  • 1
    intel is not a syntax. Assembly language is defined by the assembler, not the target. You can choose whatever syntax you want, commas or not, no reason to mimic something else for example ld [eax + 1] ebx is perfectly fine and understandable. As the author of the syntax you define if there is a case where you cant distinguish something without more symbols. – old_timer May 30 '20 at 14:19
  • 1
    @old_timer If not syntax, then what do you call the things that Intel assembly and AT&T assembly are? – Joseph Sible-Reinstate Monica May 30 '20 at 16:16
  • @JosephSible-ReinstateMonica I would call both categories *Intel* and *AT&T* either **philosophy** or **paradigma**. Assemblers based on *Intel paradigma* define field order as `instruction destination, source ,second_source`, and assemblers based on *AT&T paradigma* use `instruction source, destination`. – vitsoft May 30 '20 at 19:05
  • 3
    @old_timer: "Intel syntax" means the dialect of x86 asm syntax defined by the Intel corporation and used in their manuals. *Not* "asm for Intel-architecture / IA32" (which would not be a useful term if that's what it actually meant and had just been invented by the OP). Stack Overflow even has a tag for it (with a [tag wiki](https://stackoverflow.com/tags/intel-syntax/info)), and the OP used that tag. Of course there are multiple flavours of Intel syntax between NASM-style vs. MASM-style, but all of them require commas to separate operands. – Peter Cordes May 30 '20 at 20:36
  • 1
    @fuz Thanks, this is exactly what I'm looking for! So the commas are there to distinguish `eax[ebx]` from `'eax [ebx]` which could be hard to spot or something? – Thor Correia May 30 '20 at 20:59
  • 1
    @ThorCorreia among other things, yes. If you use a parser generator like yacc to build your assembler, you'll find that it's very hard to build unambiguous grammars without some separator between operands. – fuz May 30 '20 at 21:28
  • That's just the thing, I didn't find it difficult at all. But most likely I'm leaving out parts of the intel syntax that would cause ambiguity. – Thor Correia May 30 '20 at 22:11
  • 2
    @ThorCorreia it gets rather hard once expressions are involved (e.g. `foo-10` vs. `foo,-10`). – fuz May 31 '20 at 11:48
  • I see — is it typical to elide the spaces? – Thor Correia Jun 01 '20 at 09:01

0 Answers0