Jump to content
  • Advertisement
Sign in to follow this  
chaosgame

Interrupts in inline asm

This topic is 4851 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

At camp a week ago I was trying to write my own print() function in C++. I was using inline asm and trying to use interrupt 21h. I got errors but when i commented int 21h out, the errors stopped. The errors were runtime. The program would just hang. I was using ms visual c++ .net accademic. Can I use interrupts in inline assembly? [Edited by - chaosgame on August 4, 2005 8:54:34 AM]

Share this post


Link to post
Share on other sites
Advertisement
Interrupts should not (and cannot) be used in a 32bit Windows program. The interrupt you tried to use is a DOS software interrupt (basically a DOS API function). For obvious reasons this does not work on Windows, even if the Windows console looks like a DOS prompt to a beginner.

Share this post


Link to post
Share on other sites
Yes, you can. I've used it to break for the debugger. Is 21 a decimal value or a hexidecimal value? Make sure you know. 21 and 0x21 are different values.

EDIT:

Oh, and what Michalson said...

Share this post


Link to post
Share on other sites
You can use int 3 in user-mode, that might be the only one though.

To use the DOS stuff, you can try writing your code with debug (just type 'debug' at the command prompt). This is archaic assembly programming; you have to lay everything out yourself and even have to write your own code to save your code to disk (as a .com file, code starts at 0x100 IIRC).

Share this post


Link to post
Share on other sites
Is this just in inline asm? I wrote a hello world program entirely in assembly using int 21h and it assembled fine and ran under windows using the console.

Share this post


Link to post
Share on other sites
if you wrote it entirely in assembly, what assembler did you use? there's a good chance it compiled as a dos program that windows just emulated. when doing inline asm, your program is not being run through an emulator, therefore the dos interrupts aren't there.

Share this post


Link to post
Share on other sites
yeah i guess, but why would you want to? there are 32bit ways using windows to do anything in windows like you could in dos

Share this post


Link to post
Share on other sites
I don't know how system calls work in Windows but in Linux they interrupts are used for that. The only other way I know of that it can be done it using the SYSENTER instruction (although I'm not exactly an expert on operating system programming). So if you try disassembling the Windows DLLs you might find a way of using interrupts in Win32 programs. It wouldn't be easy to decipher though.

Share this post


Link to post
Share on other sites
My Assembly is very rusty these days, even though I was once known for having written a multithreading library for Turbo Pascal in assembly.

I think that under Protected Mode (Win32) your can be fooled into thinking you've installed you own Interrupt Handling Routines, when in fact when the hardware triggers one, it still calls the OS, who in turn may or may not call other registered handlers (yours).

There is also no real way to debug this, you'll have to go with documentation and ask around to see if that is what Windows is actually doing, a Virtual IRQ Service.

Mind you that Interrupts are not OS-specific. They occur anytime, anywhere, whatever OS is installed. An interrupt is exactly that, an interruption in the normal CPU processing that gets interrupted so that it might take a look and handle this more important thing over here.

As an example, I did an override of the Clock IRQ, which triggered a few thousand times per second (this on a 486), and with a few register manipulations, I jumped back and forth between registered threads. That's called Preemptive Multitasking, because I stopped the execution of a thread without even telling it.

If you want to code in assembly, just drop back to DOS. I think it still is easy to get a copy of Turbo Pascal (you don't need to know Pascal, just need to know how to enter assembly opcodes into de code), or C (also supports imbedded assembly) from Borland.

The compilers are lightning fast, and you won't have to deal with Win32's idiosyncrasies....

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!