李国帅于2006-3-2 9:21
说明可以在C语言中使用简单的方法调用汇编代码,其实在c中使用汇编并不见得会提高什么效率,反而影响可读性。
这种方法只在少数时候(如创建钩子函数)使用。
int main() { long HighStart, LowStart, HighEnd, LowEnd; long numhigh, numlow; __asm { RDTSC mov HighStart, edx mov LowStart, eax // put your time-consuming code here …… RDTSC mov HighEnd, edx mov LowEnd, eax //获取两次计数器值得差 sub eax, LowStart cmp eax, 0 jg L1 neg eax jmp L2 L1 : mov numlow, eax L2 : sbb edx, HighStart mov numhigh, edx } __int64 timer = (numhigh << 32) + numlow; //得出最终结果 printf("%d", timer);//105 return 0; }