🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.lang.asm.x86
2 messages
2 total messages Started by Steve Sullivan Thu, 29 Feb 1996 16:32
Catch Fixed Point Overflow in C or C++
#11
Author: Steve Sullivan
Date: Thu, 29 Feb 1996 16:32
34 lines
1538 bytes
Is it possible to have a Pentium assembler routine set up so
that fixed-point overflow in C or C++ is caught?  For example,
would either of the following approaches work?

Approach 1:
   /* here carryflag() is an asm routine to return the carry flag */
   int sum, i, j;
   long lprod, li, lj;
   sum = i + j;
   if ( carryflag()) printf("sum overflow occured\n");
   lprod = li * lj;
   if ( carryflag()) printf("prod overflow occured\n");

Approach 2:
   int sum, i, j;
   long lprod, li, lj;
   setOverCheck();   /* this is an asm routine that enables
                        "interrupt on overflow" */
   try {
      sum = i + j;      /* get exception if overflow occurs */
      lprod = li * lj;  /* get exception if overflow occurs */
   }
   catch (const char * msg) { printf("overflow occured in %s\n", msg); }

Approach 2 would be much preferred, if possible, since it doesn't
require checking after each operation as in approach 1.

Where could I find such asm code, or references on how to write it?
I don't know x86 asm, but if need be I'll learn it (sigh!).
Also, would similar approaches work to detect floating point exceptions?

Many thanks for any suggestions --

Steve Sullivan
Re: Catch Fixed Point Overflow in C or C++
#12
Author: Andy J Robb
Date: Tue, 05 Mar 1996 04:05
60 lines
2312 bytes
sullivan@indra.com (Steve Sullivan) wrote:

>Is it possible to have a Pentium assembler routine set up so
>that fixed-point overflow in C or C++ is caught?  For example,
>would either of the following approaches work?

>Approach 1:
>   /* here carryflag() is an asm routine to return the carry flag */
>   int sum, i, j;
>   long lprod, li, lj;
>   sum = i + j;
>   if ( carryflag()) printf("sum overflow occured\n");
>   lprod = li * lj;
>   if ( carryflag()) printf("prod overflow occured\n");

-----BEGIN PGP SIGNED MESSAGE-----

The carry flag is not used to detect overflow in signed arithmetic -
e.g:

(-1) + (-1)

will set the carry flag but the result can be represented correctly as
-2 in type int.  The carry flag is used in multi-precision arithmetic
to allow handling of large numbers (outside the range of a single
register).

For signed arithmetic you should look at the overflow flag.

It may be possible to stay within C or C++ by trying the reverse
operation:

sum = i + j;
if (sum - j != i) printf("sum overflow occured\n");
lprod = li * lj;
if (lj && lprod/lj != li) printf("prod overflow occured\n");

Regards,
Andy Robb.

-----BEGIN PGP SIGNATURE-----
Version: 2.6.2i

iQCVAwUBMTu9N5Pl4P16x9sNAQHnOgQAuDR4sMdUrmIFL5Mx0IZNzcAabFztwUme
yonyqFreOYRxJf4ym/ife3bmWzOJXmgkz84oorjXogqmRAafvLGSg80CiHPClIDd
Rfl0UXeRMJThNa1V1FaKdOnhR6hQfpBdVgqk7vfcS62dtzh/TpUH+BaoabYF3mfq
fUOY0YTU2sk=
=I8xm
-----END PGP SIGNATURE-----

-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: 2.6.2i

mQCNAy/MpRwAAAEEAOt6uBYqT8yv9EmqNhK8m6v+bYi8QjnGW3Bo6iU1gsMj5pa6
MHgq99c8deADbE3cbJ6uZS9v5pZE3WCf6HCQjlB5iULA5RZzMdAumd/WUzuL9UT3
B44D9EqqFIL79FlYb56v4oKFqFp1/J2bIpYUwnUvabGzGjdLrpPl4P16x9sNAAUR
tCNBbmR5IEogUm9iYiA8QUpSb2JiQHBhdmlsaW9uLmNvLnVrPrQhQW5keSBSb2Ji
IDxBSlJvYmJAcGF2aWxpb24uY28udWs+
=/wVD
-----END PGP PUBLIC KEY BLOCK-----
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads