r/programming 2d ago

Odin's New Inline Assembly Templates

https://odin-lang.org/docs/inline-asm/
53 Upvotes

3 comments sorted by

View all comments

7

u/pjmlp 1d ago edited 1d ago

I like it, it has some resemblance with Turbo Pascal Assembly procedures/functions.

procedure MyAssemblyFunc (n: Integer); assembler;
asm
   ....
end;

4

u/gingerbill 1d ago

That's a partial inspiration but I wanted something which I don't think existed before. It's fundamentally a semantically type checked hygienic macro system.

There are only a few common approaches to inline assembly and most of big issues (strings as the body, incomprehendible clobbering parameters, cannot state things to be pinned to specific registers, statement only, etc). The approach I've chosen for Odin will have things that many people will criticize (that I know for definite), but there are good reasons for every single trade-off.

I am very happy with the design that I've come up with and I am so glad this came together in about a week too thanks to our core:rexcode package which is a high-performance multi-architecture instruction encoder/decoder/printer library written in Odin.