Skip to main content
GameDev.net gamedev.net
🔒 Locked

inline asm in gcc

Started by Linux programer Feb 20, 2003 at 11:34 PM 2 replies 250+ views
Original Post
Linux programer
Linux programer
Someone hehe know how do I use assembly codes in a c++ program, compiling with gcc in linux. I wanna do something like the folowing code: void graphic_mode() { asm{ mov ax,0013h int 10h { } I want to put the vga in graphic mode, put some pixels, then come back to the original mode, but the previous code doesn''t works in gcc, I don''t know why.. Someone know how can i do it?
Null and Void
Null and Void

  1. Inline assembly is not standard C or C++. Virtually every compiler that does include it as an extension implements it slightly differently. GCC uses AT&T style inline assembly, which seems more awkward to write, but allows better integration with the code around it. Look for "AT&T inline assembly" with Google, you''ll find lots of information.
  2. I think you''ll find that Linux won''t allow you to do what you''re trying to do in the way that you''re trying to do quite that easily. Try looking into SVGAlib, or simple use something better like SDL.


Neophyte
Neophyte

  
__asm__("
movl $0x13, eax
int $0x10
"
);

Note that gcc use AT&T syntax, where (among a lot of other changes) the order of operands are reversed from what you might be used to. In addition int 10h is very unlikely to do what you expect if you''re used to programming for DOS.

-Neophyte
Prefect
Prefect
Also note that this code (even if it does work) is almost guarantueed to mess up your program.

Why? Because gcc's optimizer is very strict when it comes to register allocation. gcc's inline assembly syntax (which is documented somewhere on the GCC website) is a lot more complex than what you find in MSVC++ mostly because it is designed to interact with the optimizer.

The syntax is roughly:

asm("assembly string" : outputs : inputs : modified);

The assembly string is simply pasted into gcc's output, but operand references like %0, %1, ... are substituted.

asm("movl $0x13, %%eax\nint $0x10\n" : : : "eax", other modified registers here);

... should work because it tells the optimizer not to really on the contents of eax, etc.. after the piece of inline assembly (mind you, this is written from memory).

Just search Google for gcc inline assembly to get a number of tutorials and references apart from what's documented in the gcc manual.

cu,
Prefect

Return to the Shadows

[edited by - Prefect on February 22, 2003 9:02:13 AM]
Widelands - laid back, free software strategy

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.