timer.asm 595 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. ; x86 timer in NASM
  2. ;
  3. ; Tom St Denis, [email protected]
  4. [bits 32]
  5. [section .data]
  6. time dd 0, 0
  7. [section .text]
  8. %ifdef USE_ELF
  9. [global t_start]
  10. t_start:
  11. %else
  12. [global _t_start]
  13. _t_start:
  14. %endif
  15. push eax
  16. push ebx
  17. push ecx
  18. push edx
  19. cpuid
  20. rdtsc
  21. mov [time+0],edx
  22. mov [time+4],eax
  23. pop edx
  24. pop ecx
  25. pop ebx
  26. pop eax
  27. ret
  28. %ifdef USE_ELF
  29. [global t_read]
  30. t_read:
  31. %else
  32. [global _t_read]
  33. _t_read:
  34. %endif
  35. push ebx
  36. push ecx
  37. cpuid
  38. rdtsc
  39. sub eax,[time+4]
  40. sbb edx,[time+0]
  41. pop ecx
  42. pop ebx
  43. ret