How to divide a 64-bit number by another 64-bit number in asmjit library code?

72 Views Asked by At

I tried:

  a.mov (EAX, R10);
  a.xor_ (EDX, EDX);        /* clear the upper 64 bit */
  a.idiv (R9);
  a.mov (R8, EAX);

Both numbers are signed int64 numbers, and the result is stored in R8. The calculation should be: R8 = R8 / R9.
My code gives wrong results. How can this be fixed?

1

There are 1 best solutions below

1
Sep Roland On BEST ANSWER
R8 = R8 / R9

Both numbers are signed int64 numbers

You don't seem to load RAX from R8, and you don't sign-extend before doing the idiv instruction.

a.mov (RAX, R8);
a.cqo;
a.idiv (R9);
a.mov (R8, RAX);
a.mov (R8, EAX);

The quotient in in RAX not just in EAX.