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

4

6

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?

Tedium answered 1/3, 2010 at 6:11 Comment(0)
T
6

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.

Thibault answered 1/3, 2010 at 6:28 Comment(1)
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.Tedium
A
3

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.

Abreast answered 1/3, 2010 at 6:32 Comment(0)
C
3

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.

Callboy answered 13/4, 2010 at 16:41 Comment(0)
S
0

Under 32 bit Windows there is a virtual 86 mode and with this mode it is possible to use the older RM-software interrupts from DOS, because Windows emulate a lot of them. Also after if we have properly installed a driver for our grafikcard, then it is possible to use some of the int 10h software interupts, example for to get the vesamodelist of a vesabios on our card. Yes it is an emulation, but it get the real modenumbers and their enviroment parameters from our card, also if the changing to all those vesamodes is impossible under windows.

A 16 bit DOS application can also use the *.exe-format, but this is a MZ-format, not a PE-format.

Dirk

Scuff answered 5/5, 2013 at 16:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.