Foreign Import: asm
Using this GNU as -formatted file "hw.s":
.globl hw
.section .note.GNU-stack,"",%progbits
.section .data
output:
.ascii "Hello, world!\n\0"
.section .text
hw:
enter $0, $0
movq stdout(%rip), %rdi
leaq output(%rip), %rsi
call fprintf@PLT
movq $0, %rax
leave
ret
And this Odin file "hello.odin":
package main
when ODIN_OS == .Windows {
// can just `odin run hello.odin -file` and this works?
foreign import hello "hello.s"
foreign hello {
hw :: proc "c" () ---
}
} else {
// no foreign import yet, needs separate link
foreign _ {
hw :: proc "c" () ---
}
}
main :: proc() {
hw()
hw()
}You can compile these both to separate objects and then link them, on Linux:
$ gcc -c hw.s $ odin build hello.odin -build-mode:obj -file $ gcc -o hello hello.o hw.o -no-pie $ ./hello Hello, world! Hello, world!