All other methods are hacks, which is one of the reasons the tutorial is bogus and can easily refuse to work (for one, main = 0x1000 is not guaranteed, attempts to return from main will cause crashes).
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Well, there are other possible ways to call a C function, but none simpler than "call <function>". If you are part of some odd programming cult that dislikes "call", or are part of an obfuscated code contest:
In the first example the outb command, will always work for any input. However, in the second example you don't know that value and port will end up in the right registers, e.g al and dx.
In the first example the outb command, will always work for any input. However, in the second example you don't know that value and port will end up in the right registers, e.g al and dx.
Crap. I forgot the ioio instructions were still hobbled with regards to the supported registers.
You can use architecture specific includes and have the asm inline, with the right include file selected based on the architecture being compiled for, NickJohnson. Most ASM snippets are small bits of code that are oft repeated, and lots of times in tight loops where the cost of an extra memory reference (the push on the call instruction) is a desirable thing to optimize out.
I think that's really the main reason to use inline ASM as opposed to calling and returning from a single snippet.
--All the best,
gravaera
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.
At least in my OS, there are no instances of assembly snippets for anything other than special instructions (loading/saving control regs, invlpg, sti/cli, in/out, etc.), which are either not in tight loops or expensive to the point that a single function call overhead is meaningless. The only instance where this is not true is with semaphore operations in userspace, which are used in enough places to deter the compiler from placing them inline anyway. To me, not having to adjust anything for different compilers (my kernel compiles under gcc, tcc, and clang with no preprocessor switches) is more valuable than a couple microseconds here and there.
I can't tell why exactly this thread went OT about inline asm though...
NickJohnson wrote:Premature optimization is the root of all evil...
At least in my OS, there are no instances of assembly snippets for anything other than special instructions (loading/saving control regs, invlpg, sti/cli, in/out, etc.), which are either not in tight loops or expensive to the point that a single function call overhead is meaningless. The only instance where this is not true is with semaphore operations in userspace, which are used in enough places to deter the compiler from placing them inline anyway. To me, not having to adjust anything for different compilers (my kernel compiles under gcc, tcc, and clang with no preprocessor switches) is more valuable than a couple microseconds here and there.
I can't tell why exactly this thread went OT about inline asm though...
You are aware GCC, TCC and CLang all use the same inline assembly syntax?
I wouldn't know: I don't use inline assembly! My point is that I avoid extensions that would break compatibility between any compilers; I consider inline assembly to be an extension. Perhaps a better way to say it is that my kernel compiles with "-std=c99 -pedantic".