0

Why assembly language differs in syntax even for the same Operating system and Instruction set? For example NASM have different syntax than MASM for windows. why isn't there any standard for the syntax?

Ven
  • 73
  • 1
  • 1
  • 4
  • 2
    Because the authors didn't like the existing ones and thought they had the only correct idea about how the syntax should look. – Jester Nov 26 '15 at 12:24
  • [There is a standard](http://stackoverflow.com/a/8073217), it's just that nobody uses it. :-) – Bo Persson Nov 26 '15 at 13:34
  • Possible duplicate of [Assembly language standard](http://stackoverflow.com/questions/8065026/assembly-language-standard) – edmz Nov 26 '15 at 14:39
  • Same reason we have different, incompatible, operating systems that run on the same hardware. Personal choice. Even with things like C++ (something with a standard) compilers they try to conform but they add their own, incompatible, features to distinguish them from competitors for whatever reason (usability, marketing/sales, intentional incompatibility). – old_timer Nov 26 '15 at 16:11
  • @BoPersson : If you go the the link for that standard (*694-1985 IEEE standard*), it is now listed as `withdrawn standard` – Michael Petch Nov 26 '15 at 20:07

1 Answers1

6

For the same reason there are multiple Unix shells (bash, zsh, dash, Solaris's non-POSIX-sh /bin/sh, etc. etc.): Someone decided to make a new implementation of the language (or a mostly-compatible one) because they didn't like something about the existing language or its specific implementation. (Other than features, reasons can include: old implementation was non-Free, not portable to a platform they wanted, slow, etc.)

This would be a better question if you did some digging and found the history. Which one came first?

I always thought NASM was much more sensible, with memory refs always using [addr], and not trying to infer operand size from the declarations of symbols. I think NASM should have allowed mov reg, OFFSET symbol, so you could unambiguously write something that would assemble to mov r32, imm32 regardless of which assembler you were using (just like you can always use [mem] for MASM.) Although you can define OFFSET as a macro that expands to the empty string.

AT&T syntax came from Unix using AT&T syntax for the RISC architectures that Unix typically ran on. GNU gcc (or whoever invented AT&T syntax for x86) followed that tradition. See this excellent answer to a question about why AT&T syntax is so weird (more or less).

Community
  • 1
  • 1
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • Don't you prefer yasm? If so, then why? Second question. You wrote "for the RISC architectures that Unix typically ran on". I was not aware of this. Wasn't UNIX and C were primarily developed on a PDP11. Is that RISC? Did it have a FLAGS register? If it did not have a FLAGS register that could explain why C can't handle `adc`. – Z boson Nov 27 '15 at 20:42
  • @Zboson: I went for yasm based on x264/x265's choice. It still uses NASM syntax. I haven't compared yasm vs. nasm in detail. I think yasm's macro facilities are slightly different, but I haven't ended up writing large volumes of code in asm and needing macros. And yes, Unix and C started on PDP11. [It's *not* a RISC machine, though, and it does have a carry flag](https://en.wikipedia.org/wiki/PDP-11_architecture). I think I've read that it's assembly syntax is AT&T-style, and where they originally got the idea. – Peter Cordes Nov 27 '15 at 21:47
  • Yasm can do AT&T and Intel syntax (I think). NASM only does Intel syntax. I think Yasm used to handle multi-byte NOPS better but I'm not sure that's true anymore. Those are the only differences I am aware of. – Z boson Nov 27 '15 at 22:02
  • @Zboson: That's correct that YASM has an AT&T mode. It defaults to using long NOPs. I read once recently that NASM defaults to short NOPs, unless you use a directive to change that. – Peter Cordes Nov 27 '15 at 22:09