C++ && _asm
I'm trying to use a dos file function (ah=3Dh) to open a file using c++. but it keeps crashing.
#include <iostream.h>
void main()
{
char file[]= "text.txt";
__asm
{
mov ah,3Dh
mov al,0
lea dx,file
int 21h
}
}
i can't find my error, the program compiles and links with the Digital Mars compiler, thought it might be a problem with opening the file. but all of the other file functions crash too :ehh:
i think i have all the info where it belongs, ah has 3Dh the command to open, al has 0 to use the file for input, and i load effective address of the file name to the dx register...i wrote it in assembly also and it works fine but i doesnt work here. would appreciate any help.
[804 byte] By [
sublyme] at [2007-11-19 2:39:48]

# 2 Re: C++ && _asm
With which compiler did you use to compile the C code?
It depends on where you are running this. If you run this in an instance of the command line interpreter (cmd.exe) all 16Bit interrupts are blocked, since cmd.exe is a 32 Bit subsystem. You need to compile this with a DOS compiler, that generates DOS programms (Turbo C Compiler for example). In that case your programm will be executed in the 16 Bit subsystem, where all DOS/BIOS interrupts are enabled.
NoHero at 2007-11-10 3:57:05 >

# 3 Re: C++ && _asm
I'm no expert on what windows does with DOS applications, but I do know it's common for protected mode applications (including Windows kernel) to make callbacks for 16-bit interrupts. It's very inefficient because of the mode switching, but it's there for compatibility. Otherwise, how else could you run 16-bit apps within Windows 95 and up?
# 4 Re: C++ && _asm
The problem with the code above is, in my oppinion, that it uses an obsolete technique. The features Windows offeres for 16 bit code are there to allow older applications to run, not to allow new 16 bit applications to be developed.
The OP probably ha ssome book or tutorial he's using. My advice is to seek modern replacement soon.
# 5 Re: C++ && _asm
I'm no expert on what windows does with DOS applications, but I do know it's common for protected mode applications (including Windows kernel) to make callbacks for 16-bit interrupts. It's very inefficient because of the mode switching, but it's there for compatibility. Otherwise, how else could you run 16-bit apps within Windows 95 and up?
Yes you can and it will work, but you need a compiler which does not create a 32bit PE header. If such an header is present the application will be run in an 32bit environment were the "cli" statement cleared all the interrupts. Old DOS programs don't have such an header, and so windows identifies them as "old" 16bit software, and will run them in an first level 16bit emulation, with DOS/BIOS interrupts enabled.
NoHero at 2007-11-10 4:00:00 >
