Mail Archives: djgpp/1996/09/03/02:16:44
Xref: | news2.mv.net comp.os.msdos.djgpp:8209
|
From: | c533483 AT showme DOT missouri DOT edu
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | divide by zero under win95
|
Date: | Mon, 02 Sep 96 17:51:24 GMT
|
Organization: | University of Missouri - Columbia
|
Lines: | 94
|
Message-ID: | <50f6p1$16gc@news.missouri.edu>
|
NNTP-Posting-Host: | mizzou-ts7-09.missouri.edu
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
The following code to catch a divide by zero interrupt works perfectly under
DOS, but fails under win95. I would prefer to use win95 than have to go out
to DOS everytime to run my program. If anyone out there has experience and
can offer me some help in trying to fix it, I would appreciate it.
#include <dpmi.h>
#include <stdio.h>
__dpmi_paddr old_interrupt_vector;
typedef long Fixed32;
#define INT_TO_FIXED(x) ( (x) << 16 )
#define FIXED_TO_INT(x) ( (x) >> 16 )
Fixed32 FixedDiv(Fixed32 numer, Fixed32 denom)
{
Fixed32 temp;
__asm__
(
" xorl %%eax, %%eax \n
shrdl $16, %%edx, %%eax \n
sarl $16, %%edx \n
idivl %%ebx "
:"=a" (temp)
:"d" (numer), "b" (denom)
:"eax", "ebx", "edx"
);
return(temp);
}
void divide_overflow(void)
{
__asm__
(
" popl %ebp; \n
cmpl $0, %ebx \n
jz overflo \n
shll $4, %ebx \n
iret \n
overflo:movl $0x00000001, %ebx \n
iret "
);
}
void set_divide_interrupt(void)
{
__dpmi_paddr new_vector;
__dpmi_get_protected_mode_interrupt_vector(0x00, &old_interrupt_vector);
new_vector.selector = _go32_my_cs();
new_vector.offset32 = (long)divide_overflow;
__dpmi_set_protected_mode_interrupt_vector(0x00, &new_vector);
}
void restore_divide_interrupt(void)
{
__dpmi_set_protected_mode_interrupt_vector(0x00, &old_interrupt_vector);
}
main()
{
Fixed32 a, b, c;
set_divide_interrupt();
a = 0x80000;
b = 0x0;
c = FixedDiv(a, b);
printf("Fixed = %x, Int %d\n", c, c);
restore_divide_interrupt();
}
This is almost the same code as was posted by Graham Sturmy in the mailing
list (you can find his article in the archives). He never received a
response, but I'm hoping to fair a little better :). I can't see any reason
why it shouldn't work, but then again i'm new to djgpp. I have tried to read
the FAQ, but i find the explanation confusing.
I just wanna finish off this post by saying that I think djgpp is a great
compiler. I have had little problem in getting help, whether posted by me or
just reading problems that other people have. Thanks to everyone that's
making it and helping people like me :).
L8R,
Tom Hildrich
- Raw text -