2

Idiv performs signed division as follows:

numerator: EDX : EAX

denominator: ECX

And for output,

quotient: EAX

remainder: EDX

I know EAX -- the quotient -- could be negative. But is it possible for EDX -- the remainder -- to be negative?

ineedahero
  • 715
  • 1
  • 5
  • 10
  • 3
    On the X86 the remainder for IDIV is based on signed modulo. If you divide -8 by 5 it should yield a negative quotient (-1) and a negative remainder (-3) – Michael Petch Apr 01 '18 at 21:09
  • 1
    Yes, `idiv` implements the same signed-division / modulo semantics that ISO C requires. `idiv` came first; ISO C89 didn't require that `-5 % 2 == -1`, but allowed it as one of the possible implementation-defined behaviours. ISO C99 did standardize on the signed division behaviour implemented by x86 and many other ISAs. https://stackoverflow.com/questions/10023440/signed-division-in-c. C compilers have been compiling `x % y` to just an `idiv` the whole time, of course. – Peter Cordes Apr 05 '18 at 21:50

0 Answers0