News:

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

Main Menu

__asm to masm rdtsc

Started by maor02x, October 25, 2024, 07:10:51 PM

Previous topic - Next topic

maor02x

fixed thanks  :greenclp:

TimoVJL

why not use intrinsic
__rdtsc

main:
00000000  4883EC38                 sub rsp, 38h
00000004  0F31                     rdtsc
00000006  48C1E220                 shl rdx, 20h
0000000A  480BC2                   or rax, rdx
0000000D  4889442420               mov qword ptr [rsp+20h], rax
00000012  488B542420               mov rdx, qword ptr [rsp+20h]
00000017  488D0D00000000           lea rcx, [$SG8278]
0000001E  E800000000               call printf
00000023  33C0                     xor eax, eax
00000025  4883C438                 add rsp, 38h
00000029  C3                       ret
May the source be with you

maor02x

#2
 :greenclp:

maor02x

Quote from: TimoVJL on October 25, 2024, 07:30:00 PMwhy not use intrinsic
__rdtsc

main:
00000000  4883EC38                sub rsp, 38h
00000004  0F31                    rdtsc
00000006  48C1E220                shl rdx, 20h
0000000A  480BC2                  or rax, rdx
0000000D  4889442420              mov qword ptr [rsp+20h], rax
00000012  488B542420              mov rdx, qword ptr [rsp+20h]
00000017  488D0D00000000          lea rcx, [$SG8278]
0000001E  E800000000              call printf
00000023  33C0                    xor eax, eax
00000025  4883C438                add rsp, 38h
00000029  C3                      ret

works !!

.code
rdtsc_asm PROC
    rdtsc                     
    mov rsi, rcx           
    mov dword ptr [rsi], eax 
    mov dword ptr [rsi + 4], edx
    ret
rdtsc_asm ENDP
END
now i wonder if its possible do with 64 bit rax   rdtsc
shl rdx, 32
or rax, rdx

TimoVJL

try this  :smiley:
OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE
.code
test_rdtsc PROC
rdtsc
shl rdx, 20h
or rax, rdx
ret
test_rdtsc ENDP
END
with poasm, had to use retn
May the source be with you

maor02x

Quote from: TimoVJL on October 26, 2024, 01:19:03 AMtry this  :smiley:
OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE
.code
test_rdtsc PROC
rdtsc
shl rdx, 20h
or rax, rdx
ret
test_rdtsc ENDP
END
with poasm, had to use retn
amazing its works ! what did u do that fix it ?  :thumbsup:

maor02x

using clang also fix it so i can use _asm in x64  :azn:

unsigned __int64 time;
unsigned __int64* dest = &time;
__asm
{
    rdtsc
    shl rdx, 32
    or rax, rdx
    mov rsi, dest              // Load the address of time into RSI
    mov qword ptr[rsi], rax   // Store the combined 64-bit result in time
}


    std::cout << "Timestamp Counter: 1054980444028 " << time << std::endl;
    std::cout << "Timestamp Counter2: 1054985324299" << __rdtsc() << std::endl;