Notes on MacOS
The compilers we will write in this course all generate x86-64 assembly language as their final output. This is the assembly language used by Intel processors, and is very widely used, especially on Windows and Linux computers. Older Mac computers also use x86-64 assembly language, but newer ones (Macs which use the M1, M2, or M3 processors) use Arm64 assembly language, which is completely different from x86-64 assembly language and is not compatible with it. However, Apple has also had the foresight to provide a way to run x86-64 code on their M-series computers, called Rosetta 2. If you have an M-series Mac, you will need to install this. Start a terminal and type this:
Agree to the terms and conditions and hit return. Now Rosetta is installed!
Note
What Rosetta does is allow you to run x86-64 binary executable programs on a Mac which natively runs Arm64 code. It does this by translating the x86-64 code to Arm64 code on-the-fly. Surprisingly, there is little or no performance loss in most cases when doing this!
Having Rosetta installed is not all that is needed
in order to run your compilers and generate working executables.
You also need to be able to compile the assembly code to x86-64 executables.
Again fortunately, the clang
C compiler that Apple uses
has the ability to "cross-compile" to x86-64 executables
simply by adding the command-line arguments -arch x86_64
.
Our test scripts will do this if you add the -arm64
command-line argument
to them; this will be covered in the assignment writeups.
Note also that in order to be able to use the C compiler on a Mac at all, you have to install the Apple command-line tools by typing this:
In the future, we may offer the option of compiling to Arm64 assembly language directly. For now, Mac users should compile to x86-64 as described above and run their code using Rosetta.