views:

189

answers:

3

Here's the code:

.386 ;target for maximum compatibility
.model small,stdcall ;model
.code
    main:
        int 20h
    END main

Result: http://img705.imageshack.us/img705/3738/resultom.png

"test.exe has stopped working" - always right when it reaches the interrupt.

This is the interrupt I'm trying to use. It should simply exit the program. Others I've tried include character input/output, etc.. Nothing works.

I'm on windows 7, using masm32 with the WinAsm IDE.

There are so many cool things it seems I should be able to do with interrupts... however, it crashes whenever I try to use an interrupt - always the same way.

This seems related and possibly useful: http://stackoverflow.com/questions/1414260/dos-interrupt-in-masm-x86-assembly-crashing

...but I haven't really been able to figure anything out from it.

Any suggestions?

+2  A: 

Yep. Interrupts of this nature are specifically for MS-DOS, and as such worked in Windows ME and previous but will not work on the NT architecture except under the DOS emulator (command.com). I have no idea if this still ships with Windows 7 - I know x64 versions of Windows don't have it by default.

If you're writing Native NT Apps (you're unlikely to be doing this if you don't know what one is, but if you want to find out have a look at Mark Russinovich's Blog at MSDN) here's a list of NT interrupts and their corresponding functions: http://www.ctyme.com/intr/rb-4249.htm

Other than that, you want to call a function in the Win32 API: http://msdn.microsoft.com/en-us/library/aa383749%28VS.85%29.aspx

Edit: and in that code sample, you've not specified any options for the interrupt, done through the registers. Oh and you could get it working provided you assemble for DOS and not for Windows. If you use a Linker you'll likely be creating a Windows PE executable. However, if you're on 64-bit Windows, as I've said, don't try.

One thing you could do is install a virtual machine system such as VirtualBox or VMware and then install FreeDOS. It shouldn't take up much RAM at all and will let you experiment with assembly/dos freely.

Ninefingers
Thanks Ninefingers, I guess that makes sense. I'll definitely look into a VM, that's probably a good idea! Also, the interrupt I was using doesn't take any options (I don't think anyways), so that wouldn't be an issue.
Cam
+1  A: 

In addition to @ninefingers excellent answer - can I add the int 20H will only work for 16 bit programs. And can never be used by a .exe

See here.

Preet Sangha
+1  A: 

You have to be careful programming interrupts. If you are in anything other than RealMode (16-bit), you cannot typically reach the interrupts at the CPU level. An Interrupt Descriptor Table must be available for indexing the Interrupt Vector Table.

The IVT sits in Ring 0, where you have direct, unhindered access to hardware (CPU, Video, etc.) All applications will be running in Ring 3 (OS included). The IDT contains indexes to the IVT. This is done to protect your hardware. If you want to access interrupts from the OS, you will need to ensure that they are available to your 32-bit source.

dboarman