alt.hn

5/31/2026 at 5:59:39 PM

Writing Portable ARM64 Assembly (2023)

https://ariadne.space/2023/04/12/writing-portable-arm-assembly.html

by luu

6/3/2026 at 10:33:23 AM

> You will also need to be aware of minor differences between the Darwin ABI and other platform ABIs. A notable example is that the x18 register is reserved by the Darwin ABI and is explicitly zeroed on context switches in some cases. This register is also reserved on Android, but not on GNU/Linux or Alpine.

x18 is "the platform register", reserved for the OS. The ISA manual says not to touch it unless you know what you're doing. Also, I don't know but I could believe that android and non-googly linux use different ABIs (but probably not because everyone uses pretty much the same ABI on aarch64 from what I've seen), but surely Alpine is linux and has the same ABI as other linuxes.

by t-3

6/3/2026 at 3:34:13 PM

You know, it always rubs me wrong when I'm reading an ISA manual and it tells me how I am supposed to use general-purpose registers. Why do ISA designers even believe they're in a place to design the user-level ABIs? Like, sure, you've hardwired BL and RET to use x30, that's fine. But every other register? If I want to pass return values in x21 and x23, that's none of your business.

by Joker_vD

6/3/2026 at 11:09:01 AM

> It just requires being aware of a few differences between the Mach-O and ELF ABIs, as well as knowing what Apple-specific syntax extensions to avoid.

And completely ignoring PE and Windows on ARM.

by steve1977

6/3/2026 at 11:26:45 AM

I have been very successfully ignoring Windows on Arm since it first appeared :)

by makerofthings

6/3/2026 at 12:27:03 PM

I understand the sentiment ;) But IMHO the title of the article is still a bit misleading or incomplete.

by steve1977

6/3/2026 at 2:26:44 PM

I mean, so has Microsoft, so...

by commandlinefan

6/3/2026 at 2:39:51 PM

I like to complain about Microsoft as much as anyone, but this is simply not true. At least not since the "second coming of Windows on ARM".

by steve1977

6/3/2026 at 9:20:30 AM

How is this code portable to other platforms if it assumes that clang implies macOS?

by crest

6/3/2026 at 9:15:17 AM

[flagged]

by RomanVoropaev

6/3/2026 at 9:57:12 AM

Assembly was never portable, or do you think 6502 on Apple would work out of the box in a Gameboy or C64?

by pjmlp

6/3/2026 at 2:45:21 PM

Would be tricky to have your 6502 code running on a Game Boy as it has a Z80/8080.

by tieze

6/3/2026 at 3:49:40 PM

Should have said NES.

by pjmlp

6/3/2026 at 10:37:04 AM

In 1981, one could write a z80 assembly program for cp/m and it would run on thousands of different computer models.

by whobre

6/3/2026 at 11:23:37 AM

As someone that was alive back then already, only if you never touched the hardware directly outside the CPU.

Even the PC clones didn't had something like portable Assembly if you ventured outside 0x10h and 0x21h interrupts.

by pjmlp

6/3/2026 at 1:57:41 PM

I did it many times on CP/M and also DOS.

Never ‘touching the hardware’ was attainable for a great deal many assembly programs.

You could do a lot with 0x10h and 0x21h on DOS.

by MomsAVoxell

6/3/2026 at 2:44:50 PM

Yes, not much for games though.

by pjmlp

6/3/2026 at 12:23:30 PM

Right. I am saying there is a difference between portable and non portable assembly code. If you interacted with the machine via call 05h interface, it was portable. If you accessed computer’s video memory buffer directly it wasn’t.

by whobre

6/3/2026 at 2:01:08 PM

Good portable assembly would stub the system stuff off, anyway, and once that was done for the cpu class in focus, it was very possible to have a thin HAL and write portable code. A great deal many successful products of the era were written in pure assembly this way.

In any case, you could also get high performance multiplatform video/io assembly libraries on the market, soon enough, back in the day .. it begat a lot of Delphi units too, I seem to recall ..

by MomsAVoxell

6/3/2026 at 11:05:31 AM

of different CP/M computer models though, no?

by steve1977

6/3/2026 at 10:40:22 AM

The article is perfectly clear:

> The good news is that it is very easy to write assembly which targets Apple’s computers as well as the other 64-bit ARM devices running operating systems other than Darwin.

by foldr

6/3/2026 at 11:24:15 AM

As long as nothing outside the CPU itself gets used.

by pjmlp

6/3/2026 at 11:39:41 AM

Obviously. Who could possibly be writing ARM assembly code who is not also aware that system calls, etc. will vary across platforms?

Sometimes you do seem to make negative comments just for the sake of it.

by foldr

6/3/2026 at 12:20:43 PM

So it isn't portable after all...

by pjmlp

6/3/2026 at 4:06:15 PM

There are portable (or not) software applications, portable algorithms code, non-portable algorithm code.

Assembly based software for the Motorola 68000 /and/ the Amiga will not run on a 68000 Mac. A "polynomial based packed fastSin()" subroutine written using the XMM x64 registers will work on most x86 CPUs. The same written for the ZMM registers will not work on a number of x86 CPUs.

Surely 40 years ago we could easily assume talking about specific implementations of software applications; clearly today we see problems as being optimizable on some classes of platforms (e.g. the vectors in ARM work differently from the vectors in x64 CPUs).

by mdp2021

6/3/2026 at 12:42:54 PM

If you can understand what someone means when they talk about a “small elephant”, then you can understand what they mean when they talk about “portable assembly”. In this case, the relevant point is that you can write ARM64 assembly routines that do useful work (e.g optimized matrix multiplication, or something like that) in such a way that they’ll work correctly on a number of different ARM64 platforms.

by foldr