MSVC and Interupts (INT **h)

Started by
4 comments, last by rpg_code_master 14 years, 11 months ago
Hello All I have decided after many years to finally learn ASM (just for hobby purposes really :)) When trying to put an interupt into my C++ code, I find that it crashes due to an access exception. Looking around these forums and Google, I am getting the impression that you cannot call an interupt from C++ code, only use somthing like int86 from DOS.h. Am I right in thinking that you _cannot_ call an interupt from C++ code? My code:


__asm
{
    mov ax, 13h
    int 10h
}


OR


__asm
{
    mov ax, 4c00h
    int 21h
}


etc... Thanks, Richard Hughes
Advertisement
DOS interrupts require, well, DOS; at a complete guess I reckon you're compiling a Windows application.

I'm not familiar with DOS C++ compilers, but wouldn't it be easier to write a DOS program in straight assembly, if learning assembly is your ultimate goal?

Edit: I just noticed MSVC in your title, and apparently the last version of MSVC that supported compiling DOS applications was 1.5 - which I assume you're not using!

[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]

You can call interrupts via inline assembly in MSVC as long as you aren't targeting x64. However, about the only interrupt that won't do horrible bad things to your program on modern OSs is int 3, which will just trigger a debug breakpoint.
MSVC can't output executables for DOS, but if you compile your code with a DOS compiler (try the old Borland C++) you may get the expected results even if you're running from Windows, since your application will run in compatibility mode (Virtual x86 mode). Sure, you won't be able to do everything you would under pure DOS but, if you're just learning, it'll take a while to hit those limitations.
Get yourself a copy of the intel cpu manuals. Then read up on the difference between real mode and protected mode and the various "rings". Then read up on the low level details on which Windows operates, the difference between user mode and kernel mode. The short of it is that user mode programs aren't allowed to use interrupts directly (other than int3 as SiCrane pointed out).
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
OK, that makes sence. Thanks for that. I was wondering why I could do those things when I assembled an app using MASM and run from DOS but not MSVC.

I shall look into those things.

Thanks guys! :)

This topic is closed to new replies.

Advertisement