Well, for anyone who is tangling with similar mysteries, I finally got something to work the way I wanted it to. Thank you for the help, Adam and kinke!

The first "x" argument was stored in R8. The second "y" argument was stored in RDX. The invisible return value pointer was stored in RCX.

Here's what I was hoping to accomplish. The multiply function returns the low bits of the product in the `low` attribute of the struct and the high bits in the `high` attribute of the struct. The divide function returns the quotient in `low` and the remainder in `high`.

    struct Result {
        ulong low;
        ulong high;
    }

    Result unsignedMultiply(ulong x, ulong y) {
        version(D_InlineAsm_X86_64) asm {
            naked;
            mov RAX, R8;
            mul RDX;
            mov qword ptr [RCX], RAX;
            mov qword ptr [RCX + 8], RDX;
            ret;
        }
    }

    Result unsignedDivide(ulong x, ulong y) {
        version(D_InlineAsm_X86_64) asm {
            naked;
            mov RAX, R8;
            mov R9, RDX;
            mov RDX, 0;
            div R9;
            mov qword ptr [RCX], RAX;
            mov qword ptr [RCX + 8], RDX;
            ret;
        }
    }

Reply via email to