Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline Assembly? Include .asm? #4444

Open
bangbangsheshotmedown opened this issue Nov 2, 2024 · 3 comments
Open

Inline Assembly? Include .asm? #4444

bangbangsheshotmedown opened this issue Nov 2, 2024 · 3 comments

Comments

@bangbangsheshotmedown
Copy link

Hello,

Is inline assembly planned before 1.0?

Odin looks interesting to me, but I need to be able to write assembly

If not planned, is there a way to load .asm files?

Thanks, and sorry if that's not the right place to ask, there was a "suggest new feature" button for the issue so I figured I'd try

@Feoramund
Copy link
Contributor

I haven't ever seen any official documentation on it, but there is most definitely an asm token in the Odin tokenizer. I expect, given the low-level nature of the language, we'll get support for it eventually.

@flysand7
Copy link
Contributor

flysand7 commented Nov 3, 2024

If not planned, is there a way to load .asm files?

Yes, there is. You can "foreign import" asm files directly, and the compiler will build them (using nasm) and link them to your executable.

foreign import lib "lib.asm"

foreign lib {
   some_proc :: proc "sysv" (a: i64, b: i64) -> i64 ---
}

As far as I remember the "linking" part doesn't apply to object files, so it might only work if you're building an executable or a shared object.

@gingerBill
Copy link
Member

Inline assembly is "planned" but we are not saying what it will be precisely. This is mainly because when people say they want inline assembly, it's not obvious what exactly they really want. I understand people have used inline assembly in other compilers before and the two general approaches are to have a string literal (GCC style) or have actual parsed tokens within an asm block (traditional style).

However I am still wondering if people even want actually inline assembly or rather have a pseudo-procedure where its entire body is just assembly instead, but that body still understands basic aspects of the Odin type system.

THE FOLLOWING IS PSEUDO-CODE AND NOT A PROPOSAL

thingymabob :: asm(x: i32, y: i32) -> (z: f32, w: f32) {
    // assembly goes here
    // this isn't actually a procedure but when it is called, it will truly inline the code
}

There is the other aspect where any use of assembly is done, the file must be guarded with the specific architecture for it to be allowed, e.g. foo_amd64.odin or #+build amd64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants