Using ARM64 Assembly on Windows
How to set up a simple Aarch64 assembly development environment on Windows
Introduction
There are many tutorials on starting Arm assembly on Linux, or even or bare metal systems. I haven’t had much luck finding instructions on setting up a development environment for Arm64 assembly on Windows.
In this article, I’ll introduce the process of compiling and linking an Aarch64 assembly program. The code itself will be a subject of another post.
The example code is located in a GitHub repository nemtrif/win32armmsgbox
Tools
We are going to use the following:
Windows 11 on Arm64. It is possible to develop Arm assembly on a x86-x64 machine, but it is easier with an Arm one.
Visual Studio Code with an extension for Arm assembly such as Arm® assembly highlighting for Visual Studio Code.
Microsoft’s armasm64 assembler
Microsoft’s link.exe linker for Arm64
If you have Arm64 Visual Studio installed, the assembler and the linker will already be ready.
Using the Assembler and the Linker
To produce the executable from an assembly code file, first we need to run the assembler to produce an obj file and then the linker to produce the exe file.
Assembler
If you installed armasm64 with Visual Studio 2022 for ARM, it will probably be located in a directory like:
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.42.34433\bin\Hostarm64\arm64
The directory should be added to the PATH
so we can easily invoke the assembler. Assuming we are using Power Shell, it can be accomplished like this:
$Env:PATH += ";C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.42.34433\bin\Hostarm64\arm64"
Then the assembler can be run to produce the obj file:
armasm64 winmsgbox.asm /Fowinmsgbox.obj
Here our assembler source file name is winmsgbox.asm
and the resulting obj file is winmsgbox.obj
.
Linker
To create the executable file, we are going to invoke Microsoft’s link.exe
, which is located in the same directory as armasm64.exe and we already have it in the PATH
.
One way to ensure we have access to the input libraries (kernel32.lib, user32.lib, gdi32.lib) is to set their location to LIB environment variable. Again, from Power Shell, we can do it this way:
$Env:LIB += ";C:\Program Files (x86)\Windows Kits\10\Lib\10.0.22621.0\um\arm64"
Now we can run the linker and produce the exe file:
link winmsgbox.obj /SUBSYSTEM:WINDOWS /ENTRY:WinMain /OUT:winmsgbox.exe "kernel32.lib" "user32.lib" "gdi32.lib"
The resulting file will be called winmsgbox.exe. Running it should display a simple message box: