Interrupt 21 on Vista under Fusion?

Discussion in 'Mac Programming' started by AquaMethod, Oct 13, 2008.

  1. AquaMethod macrumors member

    Jun 17, 2008
    Wow, this is esoteric, but here it goes: does anyone know if using

    int 21h
    works in Visual C++ under Vista in a virtual machine? I need to use it for my assembly class, but my program crashes whenever it reaches the int 21h instruction. I know it's a longshot to make it work, but is it possible?
  2. lee1210 macrumors 68040


    Jan 10, 2005
    Dallas, TX
    If you're using fusion, you have an intel mac. If you have an intel mac, you can write x86 ASM under OS X. Why do you need to do this under windows? Is this some in-line assembly in a C program that uses Win32 calls as well? Is this a requirement of the class?

  3. Cromulent macrumors 603


    Oct 2, 2006
    The Land of Hope and Glory
    Unfortunately the differences between the Microsoft assembler and any either GAS or NASM under OS X are pretty big. If I was in a class and learning ASM under Windows and then had to do all my ASM coding on OS X the differences would drive me nuts. Not to mention the fact that there is next to no documentation available on Mac OS X / FreeBSD calling schemes.

    I spent weeks looking and just ended up using MASM on Windows because of the amount of documentation available for it made learning ASM so much easier. I imagine if I had the Intel compiler on Mac OS X then it would be easy enough with the Intel developer manuals though.

    Edit : Here is the thread with all the info I found and help I got:
  4. bitWrangler macrumors member

    Nov 19, 2007
    int21h allows you to access various Windows/DOS based functionality, so running it directly under OSX wouldn't do you a lot of good.

    To the OP, are you running 64 or 32bit? AFAIK, int21h is not supported in 64bit mode. Never tried it in emulation, though I don't know why this would change it's behaviour since it would likely break other stuff as well. Are you sure you're loading your params/registers correctly for whichever call you're making? Have you tried that exact code native and it works?
  5. Phil A. Moderator

    Phil A.

    Staff Member

    Apr 2, 2006
    Shropshire, UK
    IIRC, INT21h is the DOS function dispatcher (it's a long, long time since I did any DOS programming though so I could be wrong!). If that's the case, it could be that you're trying to call a function that doesn't exist under Vista and that's causing the problem. What specifically are you trying to do with your INT21h call and what are the details of the crash you get?
  6. AquaMethod thread starter macrumors member

    Jun 17, 2008
    I'm using 32-bit Vista. I haven't tried the code natively myself, but it was copied from my instructor's example, which worked fine on his machine:

    TITLE MASM Template						(main.asm)
    ; Description:
    ; Revision date:
    myDouble DWORD 1234567h
    main PROC
    	;mov ax, @data (These lines were here in his program, but
    	;mov ds, ax    they seem to make no difference in mine either way)
    	mov ah, 01h ; supposed to read a character and place ASCII value in al
    	int 21h
    	call DumpRegs
    main ENDP
    END main

    I've tried several different functions, and all of them cause the application to hang when it reaches the int 21h instruction.

    When I debug it, I get the message

    "Unhandled exception at 0x00401012 in Project.exe: 0xC0000005: Access violation reading location 0xffffffff."

    If I just run the compiled exe by itself, it crashes and Windows begins to "search for a solution" to the problem.

    According to the debugger, 0x00401012 contains the byte CDh, which
  7. kristiaand macrumors member

    Dec 5, 2007
    ok im no where near clued up on ASM etc but i figured id have ago with google. i found a link on MS's website regarding certain Int calls within windows here the link

    about halfway through the document, it states that int 21h is not supported in protected mode?

    so at a guess, i figured every version of windows since 2000 pro runs in protected mode only? (did'nt dos & win 3.1 have the ability to NOT run in protected mode?) if thats the case would that suggest that this call is never going to work on a vista system?? also which VM are you using? as it may be an unimplimented call in the OS, although the OS may support the call if the VM cannot handle what windows is asking surely that will make it fail as well?

    again i might be completly wrong on this but i figured a bit of googling and help might be handy
  8. bitWrangler macrumors member

    Nov 19, 2007
    Hmm, are you sure it's the int21 that's causing your problems and not the call to the dumper function? The location given should be the location of the fault itself not the line after the fault.

    Couple of other things to consider:

    - Check your masm/linker options, you may need to build this as a 16bit app to have it run in emulation mode.

    - int21h/ah=1 gets input from the standard input device (keyboard), it may appear to lock up, but it's just waiting for a key to be pressed, so it may be working (at least the int21 part).

    Sorry, unfortunately my masm/dos/windows programming is fuzzy at best (it's been a while, a loooong while :) ).
  9. AquaMethod thread starter macrumors member

    Jun 17, 2008
    I tried a variety of different calls, none of which worked. They did work on another Vista-using student's laptop, however.
    I've tried it with and without the DumpRegs call; it fails either way, and DumpRegs works in other programs. It's not waiting for input, though: Windows pops up an "application crashed" dialog, and it does so in the same way for every routine I try. But thanks!

Share This Page