1
votes

Okay. I want to learn how to assemble programs on my Mac (Early 2009 MBP, Intel Core 2 Duo). So far, I understand only that Assembly languages are comprised of direct one-to-one mnemonics for CPU instructions. After some Googling, I've seen a lot of terms, mostly "x86" and "x86_64". I've also seen MASM, NASM, and GAS, among others.

Correct me if I'm wrong:

  1. x86 and x86_64 are instruction sets. If I write something using these instruction sets (as raw machine code), I'm fine so long as my program stays on the processor it was designed for.
  2. NASM, MASM, and GAS are all different assemblers.
  3. There are different Assembly languages. There's the AT&T syntax and the Intel syntax, for example. Support for these syntaxes differ across assemblers.

Now, questions:

  1. As a Mac user, which instruction sets should I be concerned about?
  2. Xcode uses GCC. Does this mean it also uses GAS?
  3. If it does use GAS, then should I be learning the AT&T syntax?
  4. Is there a book I can get on this. Not a tutorial, not a reference manual on the web. Those things assume to much about me; for example, as far as I know, a register is just a little bit of memory on the CPU. That's how little I really know.

Thanks for your help.

3

3 Answers

2
votes

If you want to learn assembly language, start with the x86 instruction set. That's the basic set.

A good book on the subject is Randall Hyde's the Art of Assembly Language, which is also available on his website. He uses a high-level assembler to make things easy to grasp and to get going, but deep down it uses GAS.

I don't believe that XCode comes with any assembler, but you can for example find GAS in MacPort's binutils package.

If you just want to make programs on your Mac and you're not that interested in the life of all the bits in the CPU, you're much better off with a more high-level language like Python or Ruby.

2
votes

"I'm fine so long as my program stays on the processor it was designed for." Not really. In many cases, assembler programs will also make assumptions about the operating system they run on (e.g. when they call library functions or make system calls). Otherwise, your assumpptions are correct.

Onto questions:

  1. Current Macs support both x86 and x86-64 (aka AMD64 aka EM64T aka Intel64). Both 32-bit and 64-bit binaries can be run on recent systems; Apple itself ships its libraries in "fat" (aka "universal") mode, i.e. machine code for multiple architectures.
  2. Use "as -v" to find out what precise assembler you have; mine reports as "Apple Inc version cctools-698.1~1, GNU assembler version 1.38". So yes, it's GAS.
  3. Yes.
  4. https://stackguides.com/questions/4845/good-x86-assembly-book
0
votes

I'll answer the first question: Macs use Intel chips now, and modern processors are 64-bit.