[Oberon] DIV and MOD

Jacques Eloff eloff at cs.sun.ac.za
Thu Jul 31 06:31:01 CEST 2003


Hi

I recently noticed that the compiler (at least the 2.3.8 Linux version for 
Intel) now attempts to compensate for fractions when performing signed 
integer division, adjusting the result returned by the CPU. This requires
a minimum of three additional instructions and can create problems when
routines are written in assembler since the result will deviate in some cases 
from what Oberon says the answer should be. Does anyone know what the 
reasoning behind this change was?

Previously, something like x DIV y (with x, y: LONGINT) would result in

MOV EAX, x[EBP]
CDQ
IDIV y[EBP]

but now, the compiler generates

MOV EAX, x[EBP]
CDQ
IDIV y[EBP]
CMP EDX, 0
JGE done
DEC EAX
done:

Regards
  Jacques Eloff



More information about the Oberon mailing list