Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

AquaMethod

macrumors member
Original poster
Jun 17, 2008
65
0
Wow, this is esoteric, but here it goes: does anyone know if using

Code:
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?
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
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?

-Lee
 

Cromulent

macrumors 604
Oct 2, 2006
6,817
1,102
The Land of Hope and Glory
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?

-Lee

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:

https://forums.macrumors.com/threads/455794/
 

bitWrangler

macrumors member
Nov 19, 2007
96
0
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?

-Lee

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?
 

Phil A.

Moderator emeritus
Apr 2, 2006
5,800
3,100
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?
 

AquaMethod

macrumors member
Original poster
Jun 17, 2008
65
0
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?

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:

Code:
TITLE MASM Template						(main.asm)

; Description:
; 
; Revision date:

INCLUDE Irvine32.inc
.data
myDouble DWORD 1234567h

.code
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
	exit
main ENDP

END main


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?

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 is...call?
 

kristiaand

macrumors member
Dec 5, 2007
63
0
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

http://support.microsoft.com/kb/65128

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

UNSUPPORTED MS-DOS INTERRUPTS AND FUNCTION REQUESTS
===================================================

The following MS-DOS interrupts are not supported in protected mode
and will fail if called.

INT Description
--- -----------

20H Terminate program
25H Absolute disk read
26H Absolute disk write
27H Terminate and stay resident

The following MS-DOS INT 21H function requests are also 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
 

bitWrangler

macrumors member
Nov 19, 2007
96
0
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:

Code:
TITLE MASM Template						(main.asm)

; Description:
; 
; Revision date:

INCLUDE Irvine32.inc
.data
myDouble DWORD 1234567h

.code
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
	exit
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 is...call?

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 :) ).
 

AquaMethod

macrumors member
Original poster
Jun 17, 2008
65
0
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

http://support.microsoft.com/kb/65128

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

I tried a variety of different calls, none of which worked. They did work on another Vista-using student's laptop, however.
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 :) ).

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!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.