Article View: comp.lang.asm.x86
Article #12Re: Catch Fixed Point Overflow in C or C++
From: Andy J Robb
Date: Tue, 05 Mar 1996 04:05
Date: Tue, 05 Mar 1996 04:05
60 lines
2312 bytes
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-----
Technical Details
Message-ID:
<4hgegp$2qq@s02.pavilion.co.uk>Path:
arc1-ca.pugleaf.net!s02.pavilion.co.uk!usenetReferences:
<DnJpxH.CDw.0.net@indra.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!s02.pavilion.co.uk!usenet From: AJRobb@pavilion.co.uk (Andy J Robb) Newsgroups: comp.lang.asm.x86,comp.lang.c,comp.lang.c++ Subject: Re: Catch Fixed Point Overflow in C or C++ Date: Tue, 05 Mar 1996 04:05:25 GMT Organization: Pavilion Internet plc Message-ID: <4hgegp$2qq@s02.pavilion.co.uk> References: <DnJpxH.CDw.0.net@indra.com> NNTP-Posting-Host: poolc35.pavilion.co.uk X-Newsreader: Forte Free Agent 1.0.82