Reputation: 1137
I'm trying to use rdtsc function but i've got weird numbers. I'm trying to call this function from C code and pass the tick back to function. Can you tell me if im doing it right or not ?
Asm code:
.text
.globl czas
.type czas, @function
czas:
pushq %rbp
movq %rsp, %rbp
xor %rax,%rax;
cpuid
rdtsc
popq %rbp
ret
C code:
unsigned long long Czas;
Czas=czas();
Upvotes: 1
Views: 1698
Reputation: 58762
rdtsc
returns result in edx
:eax
even in 64 bit mode, but C calling convention expects result in rax
. You have to pack the result yourself. Note you don't typically need a stack frame for this.
Something like:
cpuid
rdtsc
shl $32, %rdx
or %rdx, %rax
ret
Upvotes: 3
Reputation: 10937
What kind of type is your function?
It should be UINT64.
rdtsc
return low 32 bits in EAX and high 32 bits in EDX register.
So is you wont result in RAX than perform:
shl rdx, 32 //left shift for 32 bits
or rax, rdx //Compose both registers in 64 bit RAX
after executing rdtsc
instruction.
Upvotes: 0