Where is there documentation on how to write inline asm?

pineapple meapineapple at gmail.com
Thu Nov 15 22:38:30 UTC 2018


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;
         }
     }


More information about the Digitalmars-d-learn mailing list