www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Interact with local variables in asm block

reply confuzzled <con fuzzled.com> writes:
Good day all,

What is the proper way to assign to accomplish this?

ulong rdtsc() {
     ulong result;
     uint* res = cast(uint*) &result;
     asm {
         rdtsc;  // Puts result in edx:eax

         // Cast our ulong's address to a 32-bit integer pointer
         // and move the register values into the correct memory locations.
         mov EAX, res[0]; // Low 32 bits
         mov EDX, res[1]; // High 32 bits
     }
     return result;
}

With this implementation, the value returned is always 0.00.

I would appreciate any help I can get.

Thanks,
-- confuzzled
Jul 04
parent confuzzled <con fuzzled.com> writes:
On 7/5/25 1:06 AM, confuzzled wrote:
 ulong rdtsc() {
      ulong result;
      uint* res = cast(uint*) &result;
      asm {
          rdtsc;  // Puts result in edx:eax
 
          // Cast our ulong's address to a 32-bit integer pointer
          // and move the register values into the correct memory
locations.
          mov EAX, res[0]; // Low 32 bits
          mov EDX, res[1]; // High 32 bits
      }
      return result;
 }
Got it: ulong rdtsc() { ulong result; asm { rdtsc; // Puts result in edx:eax mov [result], EAX; // Low 32 bits mov [result + 4], EDX; // High 32 bits } return result; } Thanks.
Jul 04