News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

RDMSR & inline assembler Visual Studio C++

Started by nonosto, January 11, 2018, 01:02:24 AM

Previous topic - Next topic

nonosto

Thank you very much, now no error in LOG with this code:


__int64 rdmsr(__int32 msr, __int32* pHigh, __int32* pLow)
{
__int32 tlow, thigh;
__asm
{
mov ecx, msr;
rdmsr;
mov tlow, eax;
mov thigh, edx;
}
__int64 value = ((__int64)thigh << 32) | (__int64)tlow;
*pLow = tlow;
*pHigh = thigh;
return value;
}


Last question please, do you think that gives the same result as this  especially the __volatile__ instruction:


uint64_t rdmsr(uint32_t msr, uint32_t* pHigh, uint32_t* pLow) {
  uint32_t low, high;

  __asm__ __volatile__ ("rdmsr"
                        :"=a"(low), "=d"(high)
                        :"c"(msr));

  uint64_t value = ((uint64_t)high << 32) | (uint64_t)low;
  *pLow = low;
  *pHigh = high;
  return value;
}


aw27

This should work as well (the return value is already in edx:eax):

__int64 rdmsr(unsigned _msr, __int32* pHigh, __int32* pLow)
{
   __asm {
      mov ecx, _msr
      rdmsr
      mov ecx, pHigh
      mov [ecx], edx
      mov ecx, pLow
      mov [ecx],eax
      leave
      ret
   }
}

nonosto