Interrupts in inline asm

Started by
12 comments, last by Anon Mike 18 years, 8 months ago
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]
"Are you threatening me, Master Jedi?" - Chancellor Palpatine
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.
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...
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).
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
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.
"Are you threatening me, Master Jedi?" - Chancellor Palpatine
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.
"I never let schooling interfere with my education" - Mark Twain
Can you compile it into a dos program? If so then would it work?
"Are you threatening me, Master Jedi?" - Chancellor Palpatine
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
"I never let schooling interfere with my education" - Mark Twain
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.
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....

This topic is closed to new replies.

Advertisement