Wrong inline assembler code generation (IMulL)

Skvarenina Peter - 5ZA51/9 skvaren@fred.fri.utc.sk
Fri May 12 05:12:00 GMT 2000


I've tried to compile this using -g and -O :
(under DJGPP 2.03, GCC 2.95.2 19991024 release)

(FixedPoint numbers using ASM)

// Result = A * B / C without loss of higher part of intermediate results
inline int Pm (int A, int B, int C)
 {
  int Result, temp;
  asm volatile ("IMulL %3\n\t"
                "IDivL %4\n\t"
                : "=a" (Result), "=d" (temp)
                : "0" (A), "r" (B), "r" (C)
                : "cc");
 }

...

int A, B, C, D;
A = 0x50000;
B = 0x30000;
C = 0x40000;
D = Pm (A, B, C);

...

And I have got SIGFPE (Division by zero). When I looked at the generated
code, it looked like this:

...

MovL  $0x50000, %EDI
MovL  $0x30000, %ESI
MovL  $0x40000, %EDX
MovL  %EDI, %EAX
IMulL %ESI, %EAX          // This will change EDX -> EDX:EAX = result of IMUL
IDiv  %EDX, %EAX          // Wrong divide

Did I something wrong ?

                                          Peter


More information about the Gcc-bugs mailing list