Assembly

Hi guys I am going to start learning assembly to get a better idea of how systems actually work,

anyway I set up a 64 bit Ubuntu virtual machine and installed the nasm assembler ,I have been reading a couple of tuts and soem are showing MASM or TASM code,and some are showing AT&T code over intel assembly

so why is there so many differences? I thoght that each cpu had their own instruction set but it seems there is different code formats such as nasm,masm,intel,AT&T

the code in the above examples are quite different

I am learning nasm,is there any good tutorials or books out there to get the grasp of nasm assembly for x86?

thanks
the operating system also matters. An executable program not only fires off commands on the CPU but it interacts with the OS memory manager and other things.

MASM is microsoft's assembly for windows on x86
TASM is borland's version of the above

NASM appears to be for unix flavors.

I don't know what ATT is right now, is that for motorola chips? Drawing a blank.

Not sure what the best resource is. I havent looked at assembly since the early multi-core machines were coming out... too long ago..

so why is there so many differences? I thoght that each cpu had their own instruction set but it seems there is different code formats such as nasm,masm,intel,AT&T

The CPU doesn't read assembly. It reads machine code.

Reading and writing machine code directly by hand is a tedious task. That's why we use an assembly language. As you have noticed, there are many different assembly languages.

The mapping between assembly and machine code is usually pretty much 1-to-1 so converting from assembly to machine code, machine code to assembly, or between two different assembly languages should be a pretty straight forward process that can be automated (assuming the same instruction set is used). The encoded machine instructions should still be the same but you might lose textual information that makes the code harder to understand.
Last edited on
I don't know what ATT is right now, is that for motorola chips? Drawing a blank.

it's the syntax used by the system assembler found on Unix operating systems, the assembler called simply "as" (/usr/bin/as on my Linux, even though in this case it's a symlink to GNU assembler "gas")

The other popular syntax on intel chips is the so-called "Intel syntax", as used by ml (the Microsoft's assembler, it hasn't been called "masm" in decades), and nasm.

You can see the difference on godbolt, by clicking the "Intel" button above the assembly window when using x86 or x64 tagerts, e.g, see https://godbolt.org/g/B6tkaX
1
2
3
4
# AT&T syntax:
demo():
  addl $1, x(%rip)
  retq
# Intel syntax:
demo():
  add dword ptr [rip + x], 1
  ret


They are the same Intel CPU commands, just using different assembly languages. Among the Intel assembly programmers, there are strongly-opinionated fans and haters of both AT&T and Intel syntaxes, but I think most professionals don't care.
Last edited on
ah, ok. I never did any assembler on an intel cpu unix, that explains the gap. Thanks!
Topic archived. No new replies allowed.