Software Archive
Read-only legacy content
17061 Discussions

Question about assembleur fonction

Hartani_A_
Beginner
830 Views

Hey 

I have a QST about assembleur in c++ 

the message : 1.#inf00 Will be displayed 

so how i can change it to my own message using assembleur fonction

0 Kudos
16 Replies
SergeyKostrov
Valued Contributor II
830 Views
>>...the message : 1.#inf00 Will be displayed That message comes from a function printf, or similar, of the CRT library. But, the message is a result of incorrect Floating Point operation and you need to understand what failed in your processing and not how that message needs to be changed. Shortly speaking, there is a bug in software codes.
0 Kudos
SergeyKostrov
Valued Contributor II
830 Views
You could also upload a piece of codes for review...
0 Kudos
Hartani_A_
Beginner
830 Views

thanks for replying
that message is displayed because i write a programme about division a simple one but we can't division by zero so if the utilisateur for example write 6/0 that message will show so i was asking if i can change that message for my own message i mean message by default show as we can not divide by zero using assembleur in c++ 

0 Kudos
SergeyKostrov
Valued Contributor II
830 Views
>>...if the utilisateur for example write 6/0 that message will show so i was asking if i can change that message for my >>own message... I think you need to do a verification of the value before doing division. Another trick is to replace all input values with zeros on values with Epsilon for a Floating Point data type used in operation ( float or double ). I use both tricks depending on an algorithm when a division by zero could happen ( or expected ).
0 Kudos
Hartani_A_
Beginner
830 Views

Sergey Kostrov wrote:

>>...if the utilisateur for example write 6/0 that message will show so i was asking if i can change that message for my
>>own message...

I think you need to do a verification of the value before doing division. Another trick is to replace all input values with zeros on values with Epsilon for a Floating Point data type used in operation ( float or double ). I use both tricks depending on an algorithm when a division by zero could happen ( or expected ).

and other trick is using if condition i mean if utilisateur use 0 show message say that we can't division par zero but if you don't mind me asking, my professor say that there is an assembleur function in dev c++ can change that message so i am looking for it. And forgive me for any annoying

0 Kudos
SergeyKostrov
Valued Contributor II
830 Views
>>...my professor say that there is an assembleur function in dev c++ can change that message... I'd like to talk to your professor... Could you arrange it, please?
0 Kudos
zalia64
New Contributor I
830 Views

You could, also:

(A) Overload the division operator between two 'Hartani_floats'

(B) Disable the  floating-point (X87) overflow exception. It is some bit in the control register, It IS NOT the exception that appears when IDIV is used.

I think Visual C++ has built-in function to do that.

It can be done, with a single assembler instruction, by 'AND' the floating-point control register  with (-1 XOR  OVERFLOW),  so as to mask this bit, where OVERFLOW is a constant with a single bit set.

To quote Intel documentation:

8.1.3.3 x87 FPU Floating-Point Exception Flags

-----------------------------------------------------------------
The six x87 FPU floating-point exception flags (bits 0 through 5) of the x87 FPU status word indicate that one or
more floating-point exceptions have been detected since the bits were last cleared. The individual exception flags
(IE, DE, ZE, OE, UE, and PE) are described in detail in Section 8.4, “x87 FPU Floating-Point Exception Handling.”
Each of the exception flags can be masked by an exception mask bit in the x87 FPU control word (see Section 8.1.5,
“x87 FPU Control Word”). The exception summary status flag (ES, bit 7) is set when any of the unmasked exception
flags are set. When the ES flag is set, the x87 FPU exception handler is invoked, using one of the techniques
described in Section 8.7, “Handling x87 FPU Exceptions in Software.” (Note that if an exception flag is masked, the
x87 FPU will still set the appropriate flag if the associated exception occurs, but it will not set the ES flag.)
The exception flags are “sticky” bits (once set, they remain set until explicitly cleared). They can be cleared by
executing the FCLEX/FNCLEX (clear exceptions) instructions, by reinitializing the x87 FPU with the FINIT/FNINIT or
FSAVE/FNSAVE instructions, or by overwriting the flags with an FRSTOR or FLDENV instruction.

 

 

0 Kudos
Hartani_A_
Beginner
830 Views

hey,

thanks to all of you for your answer but i find the answer and the only problem is this code source work only in turbo c++ and with int so i have another problem cuz division is type float so when i write type float is does'n work at all so it only work with int variable

 

#include <dos.h>
#include <stdio.h>
void interrupt (*oldhandle)();
void interrupt divide0();
int main()
{
    int a,b,c;
    oldhandle = getvect(0x00);
    setvect(0x00, divide0);
    printf("Number 1:");
    scanf("%d",&a);
    printf("Number 2:");
    scanf("%d",&b);
    c = a / b;
    printf("%d / %d = %d\n",a,b,c);
    return 0;
}
void interrupt divide0()
{
    printf("division par zero impossible REUSSIT\n");
    (*oldhandle)();
}

0 Kudos
SergeyKostrov
Valued Contributor II
830 Views
// Sub-Test 1
{
   RTbool bOk = RTtrue;

// RTfloat fV1 = 10032604.0f;        // Test-Case 1
// RTfloat fV2 =  6935401.0f;
// RTfloat fV1 = 4097.0f;            // Test-Case 2
// RTfloat fV2 = 4097.0f;
   RTfloat fV1 = 777.0f;             // Test-Case 3
   RTfloat fV2 = 0.0f;

   RTfloat fR = 0.0f;
   RTint jmpret = -1;
                                     // Unmask all floating-point exceptions
   #if ( defined ( _WIN32_BCC ) )
   CrtControl87( _RTFPU_CW_DEFAULT, _RTFPU_MCW_EM );
   #else
   CrtControl87( 1, _RTFPU_MCW_EM );
   #endif

   #if ( defined ( _WIN32_WCC ) )
   if( CrtSignal( _RTSIGFPE, ( RTvoid (          * )( PRTint ) )SignalHandler ) == _RTSIGERR )
   #else
   if( CrtSignal( _RTSIGFPE, ( RTvoid ( _RTcdecl * )( PRTint ) )SignalHandler ) == _RTSIGERR )
   #endif
   {
        bOk = RTfalse;
        CrtPrintf( RTU("Failed to Set a Handler for Detection of a Floating Point Error\n") );
   }

// CrtPrintf( RTU("Adding %.1f and %.1f - [ Expected: 16968005.0 ] [ Calculated: %.16f ]\n"),
//      fV1, fV2, ( fV1 + fV2 ) );
// CrtPrintf( RTU("Multiplying %.1f by %.1f - [ Expected: 16785409.0 ] [ Calculated: %.16f ]\n"),
//      fV1, fV2, ( fV1 * fV2 ) );
   CrtPrintf( RTU("Dividing %.1f by %.1f\n"), fV1, fV2 );

   if( bOk == RTtrue )
   {
        jmpret = CrtSetjmp( jmpbuf );
        if( jmpret == 0 )
        {
      //   fR = fV1 + fV2;         // Test-Case 1
      //   fR = fV1 * fV2;         // Test-Case 2
           fR = fV1 / fV2;         // Test-Case 3
        }
        else
        {
           SignalInfo();
        }
   }
}

 

0 Kudos
SergeyKostrov
Valued Contributor II
830 Views
>>...i have another problem cuz division is type float so when i write type float is does'n work at all so it only work with int variable... The piece of codes that uses Interrupt 0 is a very-very obsolete for solving divide by zero cases. Even on 16-bit MS-DOS operating systems it wasn't widely used and a SIGNAL-based solution was used instead.
0 Kudos
SergeyKostrov
Valued Contributor II
830 Views
Follow up... >>...when i write type float is does'n work at all so it only work with int variable... When you divide an integer IA by integer IB a general purpose DIV instruction ( aka Unsigned Divide ) is used and it stores a result in General Purpose registers, for example, in EAX:EDX, and Interrupt 0 is called if IB is 0. When you divide a floating point number FA by a floating point number FB a Floating Point Unit ( FPU ) FDIV instruction is used and it stores a result in an FPU register STx, for example in ST0, and a floating point exception is thrown when FB is zero. The Interrupt 0 does not handle divide-by-zero FPU exceptions.
0 Kudos
Hartani_A_
Beginner
830 Views

yes it semas that we have the solution thancs a lot for your support and advices and for evreything

0 Kudos
SergeyKostrov
Valued Contributor II
830 Views

>>...when i write type float is does'n work at all so it only work with int variable...

You can solve that problem in a different way:

#include <dos.h>
#include <stdio.h>

void interrupt (*oldhandle)( void );
void interrupt divide0( void );

int main( void )
{
     float a, b, cf;
     int ci;
     oldhandle = getvect( 0x00 );
     setvect( 0x00, divide0 );
     printf( "Number 1:" );
     scanf( "%f", &a );
     printf( "Number 2:" );
     scanf( "%f", &b );
     if( b == 0.0 )
          ci = ( int )a / ( int )b;
     else
          cf = a / b;
     printf( "%f / %f = %f\n", a, b, c );
     return ( int )0;
 }

void interrupt divide0( void )
{
     printf( "Division par zero impossible REUSSIT\n" );
     (*oldhandle)();
}

 

 

0 Kudos
Hartani_A_
Beginner
830 Views

Sergey Kostrov wrote:

>>...when i write type float is does'n work at all so it only work with int variable...

You can solve that problem in a different way:

#include <dos.h>
#include <stdio.h>

void interrupt (*oldhandle)( void );
void interrupt divide0( void );

int main( void )
{
     float a, b, cf;
     int ci;
     oldhandle = getvect( 0x00 );
     setvect( 0x00, divide0 );
     printf( "Number 1:" );
     scanf( "%f", &a );
     printf( "Number 2:" );
     scanf( "%f", &b );
     if( b == 0.0 )
          ci = ( int )a / ( int )b;
     else
          cf = a / b;
     printf( "%f / %f = %f\n", a, b, c );
     return ( int )0;
 }

void interrupt divide0( void )
{
     printf( "Division par zero impossible REUSSIT\n" );
     (*oldhandle)();
}

 

 

 

hey i compileyour code source and the result is:Nouvelle image bitmap.bmp

0 Kudos
SergeyKostrov
Valued Contributor II
830 Views
>>...hey I compile your code source and the result is... It is a really small mistyping error in my example and fix it. If you're a student and learning how to do programming then you need to learn how to solve problems. Take into account that "Google It Guys" or "Stackoverflow It Guys" usually do Not survive in software companies.
0 Kudos
Hartani_A_
Beginner
830 Views

Sergey Kostrov wrote:

>>...hey I compile your code source and the result is...

It is a really small mistyping error in my example and fix it.

If you're a student and learning how to do programming then you need to learn how to solve problems. Take into account that "Google It Guys" or "Stackoverflow It Guys" usually do Not survive in software companies.

 

and that what i was doing and i finish it thanks a lot you save me for real thank you

0 Kudos
Reply