Skip to content

Instantly share code, notes, and snippets.

@dimapaloskin
Forked from n2o/nasm_m1.md
Created August 27, 2024 23:04
Show Gist options
  • Save dimapaloskin/41ad7b5616c6f57ca17ad89573b68c04 to your computer and use it in GitHub Desktop.
Save dimapaloskin/41ad7b5616c6f57ca17ad89573b68c04 to your computer and use it in GitHub Desktop.
Compiling x86_64 assembly program on M1 Mac

If you have an M1 Mac and want to compile and execute x86_64 assembly code, make sure you install Rosetta 2 and nasm (brew install nasm).

Than, take a 64 Bit assembly program, e.g. from this tutorial page (https://cs.lmu.edu/~ray/notes/nasmtutorial/) in Section "Your First Program" for macOS, save it to a file called hello.asm.

Compile, link and execute the program:

nasm -f macho64 hello.asm
ld hello.o -o hello -macosx_version_min 11.0 -L /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib -lSystem
./hello
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment