NO.
Do
not write inline assembly like the manners suggested so far, especially by Bender!
First of all search the wiki and read the article:
http://wiki.osdev.org/Inline_Assembly
Second, reuse existing inline assembly from the wiki that has been peer-reviewed and verified as safe (hopefully):
http://wiki.osdev.org/Inline_Assembly/Examples
Third, learn the C programming language. Your example code looks truly badly written by someone that doesn't know it. Don't expect to succeed at this, especially not at inline assembly, until you know your tools well. I'm not even sure all of the registers you used actually exist.
Fourth, inline assemby should be treated as extremely dangerous and fragile. You must be an expert in inline assembly to do it reliably and precisely. It is a very powerful tool that lets you cooperate with the compiler code generation and you can achieve very good results if you do your job well. However, if you lie to the compiler in any way, the optimizer can do truly horrific things to your inline assembly that seems perfectly reasonable to the compiler. The compiler does look look at your inline assembly at all except to substitute registers and makes no attempt to understand it.
Fifth, the inline assembly uses AT&T syntax (same as the GNU assembler) as preprocessed by GCC. You need to prefix registers with % (double %% actually if you really don't want to use virtual registers) and use the correct operand order. You can change this using particular gcc options, but that is obviously really bad style.
Sixth, the function stack frame and register are the property of the compiler. Do not assume that particular registers contain particular values in your inline assembly unless you told the compiler to do so in your input list. Do not assume that the local stack frame has a particular layout and that you can access variables without them being in the input list. Do not assume you can sneak values in particular registers behind the back of the compiler between inline assembly statements. Unite them if needed.
Seventh, read carefully what Bender wrote and remember that it is is unsafe bullshit. He uses ABI knowledge but forgets the existence of the compiler and optimizer and that C is not a high-level assembler. Do not trust and thank people that appear to know what they are talking about when they obviously don't.
Eigth, don't do inline assembly. It's for experts only, and I mean experts that really read the GCC documentation (that is unfortunately hard to find good information on inline assembly for i386 in) and carefully verified its correctness. Use a normal assembly file instead.
Nineth, use compiler builtins and compiler headers or extensions instead. Unlike inline assembly, the compiler understands those at a much deeper level and can do some truly amazing optimizations.
Tenth, don't use inline assembly for the sake of performance. You can usually write normal C that does the job just as well and that future compilers can optimize really well.
Eleventh, the inline assembly isn't correct just because it happens to work. You may not have triggered the optimization case where your lies cause trouble. You should carefully verify you told the compiler the truth.
Finally. Be careful and safe. You can make some really useful constructions with inline assembly, but it is a tool that easily backfires and you can construct horrificly ugly hacks using them that didn't need to exist in the first place. Be careful who you trust. Learn C. Cooperate with your compiler.
See also the System V ABI specifics if you are using a i686-elf cross-compiler:
http://wiki.osdev.org/System_V_ABI
- Your local committee for prevention of compiler crime.