Recently i've been writing a simple compiler in C++ that translates the code written in my custom language into nasm for linux. Everything works fine, I've written a sliding puzzles solver in my language too, but i need to know how much time it takes. Do anyone know how to make a timer in NASM? Thanks!
Asked
Active
Viewed 205 times
0
-
The same way you would in C in Linux... – Prof. Falken Aug 03 '15 at 19:00
-
Can you explain more? – Mattia F. Aug 03 '15 at 19:02
-
[This](http://stackoverflow.com/a/6636376/5162988) *might* be what you're looking for. – R2-Dequeue Aug 03 '15 at 19:14
-
Yes but with that method i can get the number of seconds, i need much more precision – Mattia F. Aug 03 '15 at 19:32
-
So add the precision requirement to the question – Prof. Falken Aug 03 '15 at 20:31
-
Do you have a method to call system-calls in general in your compiler? If so, gettimeofday or similar should be available. – Mats Petersson Aug 03 '15 at 20:54
-
Or it's modern equivalent: `clock_gettime`? – Mats Petersson Aug 03 '15 at 20:56
-
Thanks, gettimeofday works, but still I haven't understood which value tv_usec contains (http://man7.org/linux/man-pages/man2/gettimeofday.2.html): i always get >1 million number. If that value in in microseconds, it's more than a second... (no sense?) – Mattia F. Aug 09 '15 at 21:28
1 Answers
0
From this page it seems that clock_gettime
is the best option on Linux.
This blog post has some NASM code that demonstrates how to call the function and this SO answer shows how to link to the function in glibc, as another option.

Community
- 1
- 1

R2-Dequeue
- 638
- 1
- 5
- 15