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?