Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which assemblers are used on M1 Macs ? Where is the canonical documentation?

I'd like to get a better idea which assemblers are actually working on M1/M2 MacOs machines, such as MacBook Pros.

  1. As I understand it, the only possible assembler I can use is the Apple provided 'as'. Gnu Assembler ('gas') is no longer supported on M1+ machines: 'as -Q' says so. But many websites mention that the Apple assembler is really not maintained, and that there is a switch to llvm-clang assembler, for which I find no useful documentation (for running the assembler, not building a compiler).

True ?

  1. I'm looking into documentation, and I mostly only find the "Mac OS X Assembler Guide". And a very old copy at that, I'm not even sure where to get a recent version.

That seems OK, but it seems not entirely complete – for instance, you can have macros with named parameters instead of just using $0, ... $n in 'as'. Not mentioned in the guide.

Are there any good pointers to porting from gas to the apple assembler ? Known problems and solutions ?

E.g., in 'gas', I believe I can redefine symbols with .set, but not with 'as'. I'm really a very inexperienced assembler amateur, so some canonical resources would be great. As I see it today, assembly programming on M1 Mac's is more dark arts than a science.

Thanks for any enlightenment.

like image 751
Klapaucius Klapaucius Avatar asked Oct 13 '25 05:10

Klapaucius Klapaucius


1 Answers

I wanted to document what I found so far:

  1. the old assembler guide from apple is (per Jake 'Alquimista' LEE) most likely not useful, as this guide is most likely not based on the clang assembler used by M1 Macs). No new doc found on the new SDK site.

The documentation likely to be mostly accurate seems to be https://developer.arm.com/documentation/100067/0611/armclang-Integrated-Assembler.

There's also https://developer.arm.com/documentation/100068/0612/migrating-from-armasm-to-the-armclang-integrated-assembler/symbol-definition-directives and https://developer.arm.com/documentation/100068/0612/migrating-from-armasm-to-the-armclang-integrated-assembler/overview-of-differences-between-armasm-and-gnu-syntax-assembly-code?lang=en

  1. Most likely, Apple is using the clang assembler more or less directly. It is similar to the gnu assembler, but not identical. For instance, jonesforth uses a feature where you can .set a symbol over and over to non-absolute values like labels to build a linked list of commands - that works in GNU assembler, not in llvm (at least the apple assembler). Also, the apple assembler does not allow multiple statements in one line separated by ';', which is a huge pain in the neck when porting large assembly files making extensive use of this.

  2. I believe that the llvm project has source code in github, specifically assembler parsing here: https://github.com/llvm/llvm-project/blob/92920c4fe3e29640e45153f3048105970b5b1e42/llvm/lib/MC/MCParser/AsmParser.cpp

I realize this is fairly incomplete, but I will update the answer should I ever get a useful response on the apple dev forums or directly from Apple support.

like image 75
Klapaucius Klapaucius Avatar answered Oct 14 '25 20:10

Klapaucius Klapaucius



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!