Search code examples
assemblycrashinterruptlow-levelmasm32

Why is my masm32 program crashing whenever I try using interrupts?


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: DOS Interrupt in masm x86 assembly crashing

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

Any suggestions?


Solution

  • 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.