Build x64 and ARM64 assembly with dotnet build.
AsmSdk turns assembly into shared libraries, static libraries and programs for Windows, Linux and macOS, shares them as versioned NuGet packages, and keeps them in the same solution as your C#, which gets the build of the platform it runs on. The assemblers and linkers come with it.
hello_add, assembled for Linux and macOS:
lea eax, [rdi + rsi] is 8D 04 37 and ret is
C3. The teal blocks are the first bytes of sum_i32. Both functions
come from the samples on this site.Three files to a shared library
-
Name the SDK in
global.json{ "msbuild-sdks": { "AsmFoundation.Sdk": "0.3.0" } } -
Add
Hello/Hello.asmproj<Project Sdk="AsmFoundation.Sdk"> <PropertyGroup> <AssemblyName>hello</AssemblyName> <RuntimeIdentifiers>win-x64;linux-x64;osx-x64</RuntimeIdentifiers> </PropertyGroup> </Project> -
Run
dotnet buildHello -> bin/Debug/freestanding/win-x64/hello.dll Hello -> bin/Debug/freestanding/linux-x64/libhello.so Hello -> bin/Debug/freestanding/osx-x64/libhello.dylibEvery
*.asmnext to the project is assembled for each x64 platform, the way every*.csis compiled in a.csproj. A*.sfile adds ARM64. Walk through it.
What a build does
You write
*.asm, *.s, include/*.incx64 and ARM64 sources and public include files<ProjectReference>other assembly projects<PackageReference>assembly libraries, by versionRestoreAsmFoundation.Toolchain for this machine, from NuGet
AssembleNASM 3.02 and llvm-mc 23.1.5, per platform, one run per changed source
Linklld 23.1.5 and llvm-ar, with deterministic output
You get
hello.dll, libhello.so, libhello.dylibshared librarieshello.lib, libhello.astatic librarieshello-app.exe, hello-appprogramsHello.1.0.0.nupkgfrom dotnet packUsed by
C# through
[LibraryImport]Python through
ctypesother assembly projects and packages
The ecosystem
- KvAsm
- A gRPC key-value server in assembly. Its unmodified source builds with AsmSdk.
- GrpcAsm
- A gRPC server and client in assembly, built with AsmSdk: its NASM, C and .NET APIs work today, Python is next (in development).
- asmsdk for Claude Code
- A plugin that teaches Claude Code the SDK, with a scaffolder, a linter and an ELF inspector.
The toolchain
- NASM 3.02
- Assembles the x64 sources. The official binary on Windows, built from source on Linux and macOS.
- llvm-mc 23.1.5
- Assembles the GNU-syntax sources: ARM64.
- lld 23.1.5
- Links for Windows, Linux and macOS: lld-link, ld.lld and ld64.lld in one program.
- llvm-ar, llvm-readobj
- Write deterministic archives and inspect what came out.