Hacker News new | ask | show | jobs
by cloogshicer 836 days ago
Interesting, I'm curious though, once you do drop down to the ASM layer, how do you ensure that this code doesn't get overwritten by new compiler output? Or is this something you somehow include in the compile step?
3 comments

Typically you'd have some assembly functions in a separate file. Compile to an object file and link it, as you'd do with a separate C file.

If you want to insert assembly snippets inside a C function, many C compilers have an inline assembly feature. For simple snippets, the C compiler can figure it out. For more complex things, you there are ways to tell the C compilers which registers you're using, so it does not step on your toes.

Thank you for explaining!
Assembly can either be inline with the C code or in a separate file. It's just source. Of course, if you really want to have fun with breaking abstractions, check out linker script files. That's for when you absolutely need different bits of code and data in specific parts of the application. Fun!
In my experience (admittedly limited) you include the assembly in the compile step. Your linker hopefully puts everything together so you can talk to yourself