386 Interrupts and C++


by yeestrada
Tags: interrupts
yeestrada
yeestrada is offline
#1
Apr21-10, 03:06 PM
P: 3
Hello every body, I have a doubt, I'm working right now with a micro 386, so I'm using it's interruptions, but I want to link c++ with assembly code and I don't know how can I use an interruption inside c++, I hear that is not possible to execute assembly code form a high level language, I,m not so sure of it. Can someone ask me if is possible to execute an interruption of assembly code form c++ and how can I do it?

thanks for your help

yordan
Phys.Org News Partner Science news on Phys.org
SensaBubble: It's a bubble, but not as we know it (w/ video)
The hemihelix: Scientists discover a new shape using rubber bands (w/ video)
Microbes provide insights into evolution of human language
Borek
Borek is online now
#2
Apr21-10, 03:32 PM
Admin
Borek's Avatar
P: 22,709
Last time I wrote my own interrupt handler was about 13 years ago, so I have no idea how these things are done today. But I am more than sure that you need to specify OS and compiler before you can get any help.
rcgldr
rcgldr is offline
#3
Apr21-10, 03:33 PM
HW Helper
P: 6,931
You can mix C++ and assembly code. If you're writing interrupt code, you need to avoid sharing variables between task code and interrupt code. I don't know what type of operating system you're micro 386 is using, but you'll need to use it's functions to communicate between interrupts and any task used by the micro operating system.

You'll also want to write some dummy C++ code that calls the C++ interrupt handler, then have the compiler output the assembly code from that dummy code, so you know the naming and calling conventions used by your compiler.

I've written and/or worked with a few small operating systems, and these only needed a small amount of assembly code in the low level interrupt handlers, with a call to a function (perhaps via a pointer to function) written in C. The cpu and OS specific context switch stuff is handled in assembly, while most of the I/O and logic is in the C function.

If you buy an OS, then the assembly code is already written, usually includes some basic example interrupt handlers written in C, and you just write the C part of the code. This could be done with C++ as well, but I personally haven't worked in such an environment.

yeestrada
yeestrada is offline
#4
Apr22-10, 02:29 PM
P: 3

386 Interrupts and C++


I'm now working with Windows XP sp2 and I'm programing with c++ builder 6. I was trying to do it with C# code, but as I understand, C# has its own assembly language. I'm a beginner on this topic, so I'll be very grateful if someone can provide an example (can be developed in c# or C++).

thanks everybody

yordan
rcgldr
rcgldr is offline
#5
Apr22-10, 03:02 PM
HW Helper
P: 6,931
I'm going to assume that you don't mean actual interrupts, but just want to mix assembly code and C or C++ code. Although inline assembly is rare these days, there's no reason you can't write functions in assembly code than can be called and/or make calls to C or C++ functions. To deal with the naming and register usage conventions, I'd recommend creating a small C code function and using a compiler option to produce assembly code to get you started.

To access interrupts in Windows XP, you need to create and install a device driver. You'll need to download and install the WDK (windows driver kit). I haven't done this in years. I did a device driver for Windows NT, with what was called DDK (device driver kit), and used remote debugging, using two computers. The OS and CPU specific interrupt stuff are handled within Windows XP (some of this would be assembly code), and you supply pointers to C functions to handle interrupts for your driver.

If you're only using Windows XP to create code that runs in a different environment, then you can mix assembly, C, and C++ functions. You'll need some method to convert the .EXE image into a binary image for the target environment, which I assume the c++ builder 6 includes.
yeestrada
yeestrada is offline
#6
Apr22-10, 03:48 PM
P: 3
Let me try to explain, I just want to use an interruption to show how is possible to connect asm code with a high level language, I'm in a course of assembly and this is a homework, I just want to use the graphic mode (int 10h) or simply use the int 21h to show an example. That's why I'm trying to insert asm code in c++ code.

thanks again

yordan
Mark44
Mark44 is offline
#7
Apr22-10, 04:34 PM
Mentor
P: 21,067
I'm pretty sure that you won't be able to do what you want to do running Windows XP, especially the old DOS int 21h functions, and maybe the int 10h graphics functions. The last Microsoft OS that supported them was Windows 3.1 just prior to Windows 95.

If I'm wrong about any of this, hopefully someone will jump in and correct me.
Borek
Borek is online now
#8
Apr22-10, 05:20 PM
Admin
Borek's Avatar
P: 22,709
It is more complicated than that. I have just checked - my program written in Turbo Pascal and compiled on May 17th, 1995, switched my ATI graphic card into VGA 0x12 mode, modified palette and displayed whatever it should display - under XP.

If anyone want's (is brave enough) to try - I can send you both source and exe (6kb together). This is a simulation of sand falling down in liquid - so grains are getting separated depending on their size, as the color depends on the grain size, they create interesting landscapes. I have seen something like that made of sand in water, together with some air, placed between two sheets of glass. Whene you rotate it, air goes up, blocking sand, liquid goes down, then sand starts to fall between air bubbles, so it pours down in thin line. Bubbles move, so sand pours down in random places and for a random periods of time.

Code is just an attempt to recreate the effect, so it has nothing to do with physical accuracy.

Unfortunately, after graphic mode is changed, PrtScr no longer copies screen content to clipboard, so I can't show you the effect.
rcgldr
rcgldr is offline
#9
Apr22-10, 11:44 PM
HW Helper
P: 6,931
Quote Quote by yeestrada View Post
I just want to use an interruption to show how is possible to connect asm code with a high level language
You mean issue a BIOS (Int 10->20h) or MSDOS (int 21h) call? Those should work in XP, although you'll probably need to be in full screen dos console mode for VGA calls to work.

Programs such as Glidos can also intercept these interrupts, probably via the debugger interface, but I'm not sure how it's done.

You could have the assembly code do something simpler, like writing your own strchr() function in assembly.
Unit
Unit is offline
#10
May19-10, 03:13 PM
P: 182
Quote Quote by Mark44 View Post
...The last Microsoft OS that supported them (the old DOS int 21h functions, and maybe the int 10h graphics functions) was Windows 3.1 just prior to Windows 95.

If I'm wrong about any of this, hopefully someone will jump in and correct me.
Actually, I'm running Windows 98SE, and, with nasm, I've used both BIOS INT 10h and DOS INT 21h, with AH containing usually 09 -- this outputs a '$'-terminated string located at DS:DX.


Also, OP: Delphi can connect to asm code, see here: http://delphi.about.com/library/bluc/text/uc052501a.htm
Borek
Borek is online now
#11
May19-10, 03:26 PM
Admin
Borek's Avatar
P: 22,709
Quote Quote by Unit View Post
Actually, I'm running Windows 98SE, and, with nasm, I've used both BIOS INT 10h and DOS INT 21h, with AH containing usually 09 -- this outputs a '$'-terminated string located at DS:DX.
I guess that's not when running native Windows program, but when using some kind of DOS box or whatever it was called.
mgb_phys
mgb_phys is offline
#12
May19-10, 03:29 PM
Sci Advisor
HW Helper
P: 8,961
You can't directly access interrupts in windows >98.
You need to write a protected mode device driver in newer versions to access memory directly, even then you can't (IIRC) access bios interrupts.


Register to reply

Related Discussions
interrupts on 8051 Electrical Engineering 2