Help understand the DIV instruction in x86 Embedded

When reading some source code in a GNU project, I came across this bit of inline assembly:

__asm__ (
  "divq %4"
  : "=a" (q), "=d" (r)
  : "0" (n0), "1" (n1), "rm" (d)
);

Here the variables q, r, n0, n1and dare 64-bit integers. I know enough assembly to understand the essence of this, but some details I'm not sure.

What I understand:

We divide the contents of the RAX register by d, putting the factor in qand putting the remainder in r.

What? I do not understand

  • Why are there three entrances here? We only need to introduce a dividend and a divider, so what use can there be 3 inputs?
  • I cannot determine which of the input is a dividend. More generally, I don’t see anything being loaded into the RAX register, since it knows what to divide by what?
+5
2

:

: "0" (n0), "1" (n1), "rm" (d)

"0" "1" rax rdx - :

: "=a" (q), "=d" (r)

div RDX:RAX. ( , .., rax rdx) , "rm". rdx, rax, divisor - 3 .

, : n1:n0 / d n1:n0 - , RDX:RAX.

+4

, div a d, rax rdx divq. a n0, 0- , a. n1 - d, , , .

0

All Articles