Search code examples
linuxassemblysyntaxcompiler-constructionnasm

Different assembly syntaxes for same cpu?


I've decided to learn assembler through online tutorials.

I've come across this one that uses the NASM compiler, which most other tutorials seem to as well: http://www.tutorialspoint.com/assembly_programming/index.htm

I've also come across this youtube series "Assembly primer for hackers" https://www.youtube.com/watch?v=K0g-twyhmQ4&list=PLue5IPmkmZ-P1pDbF3vSQtuNquX0SZHpB This one uses what the guy describes as the 'generic linux compiler' (owtte). The commands for compiling go something like this:

as -o file.o file.s

Where file.s is the assembly source code. Followed by:

ld -o file file.o

Where file is then the executable.

Each of the tutorials uses a different syntax (e.g. a register in the latter tutorial is always preceded by %. NB. There do appear to be less superficial differences in the syntax than this as well). Are these syntaxes decided by the individual compiler?

I was also initially confused when I tried to compile code from the NASM tutorial with the latter method. I was always under the impression that the instruction set had to depend on the CPU and it therefore shouldn't matter which compiler I use. I've just concluded that it's merely differences in syntax but is that correct?

I'm running a Linux computer, by the way, on kernel 4.1.6.

My main question is really which syntax do I use? Is it just a matter of choice? Is one more widely used than the other? Thanks for any help.


Solution

  • Each of the tutorials uses a different syntax (e.g. a register in the latter tutorial is always preceded by %. NB. There do appear to be less superficial differences in the syntax than this as well). Are these syntaxes decided by the individual compiler?

    Yes, different assemblers (= assembly language compilers) might use different assembler language syntax although they provide code for the same processor and platform.

    My main question is really which syntax do I use? Is it just a matter of choice? Is one more widely used than the other?

    One assembler, like NASM, might go for a wide range of processors and platforms, in this case you would benefit from learning its syntax when you need to work with several processors or platforms.

    In other cases it might be better to stick with the assembler of some prominent vendor, because it is widely used and you can find more example code on the net for it which might help you with your development.

    Last not least you might simply prefer a particular assembler because you like its features or syntax.