flat assembler
Message board for the users of flat assembler.
Index
> Windows > [help] Coding a sleep-delay function without API |
Author |
|
XY2k 14 Dec 2006, 15:15
Hi Community,
i want like coding a sleep-delay function (5sec.) in asm but without any api. Have somebody an idea ? regards, XY2k |
|||
14 Dec 2006, 15:15 |
|
Plue 14 Dec 2006, 16:45
Basically you can't if you don't have access to the timer interrupt or the api.
|
|||
14 Dec 2006, 16:45 |
|
Tomasz Grysztar 14 Dec 2006, 17:28
Well, if you know what clock your processor has, you may try the RDTSC.
|
|||
14 Dec 2006, 17:28 |
|
Plue 14 Dec 2006, 20:46
The point with Sleep() is that your process doesn't use any CPU, but it will use CPU time if you constantly check the time ... unless you wait with Sleep() in between everytime you check
Waiting for five seconds <> looping for five seconds. |
|||
14 Dec 2006, 20:46 |
|
Tomasz Grysztar 14 Dec 2006, 22:34
This of course cannot be achieved without task-switching (well, there is also HLT, but it's a privileged instruction), what is out of reach of your process itself, even if you had access to timer interrupt.
The existence of the solution depends on what the need really is (the question wasn't much detailed). |
|||
14 Dec 2006, 22:34 |
|
kohlrak 14 Dec 2006, 23:38
I agree, Sleep is efficient as it is and trying to code something else is not going to work well... you might be able to recode the same thing, but since you're basing it on a system with an inturnal clock (GetTickCount) it'll probably be best to use it. The system calls are pretty safe to use, and we have them there and they're free so we my as well use them unless we're coding our own OS kernel.
|
|||
14 Dec 2006, 23:38 |
|
XY2k 18 Dec 2006, 14:45
Sorry guys and thx for answers ,
i don´t mean without any API, i mean without sleep api! I want like try to recode the sleep function, so i can do it with GetTickCount but i dont have an idea how i can realize it I´m happy when somebody can give me a peace of code regards, XY2k |
|||
18 Dec 2006, 14:45 |
|
kohlrak 18 Dec 2006, 21:21
Well, if some one gives you the code how can you recode it yourself?
|
|||
18 Dec 2006, 21:21 |
|
f0dder 18 Dec 2006, 23:14
Doing it with GetTickCount will be less accurate, and will keep you in a CPU-using polling loop, whereas Sleep() suspends your thread (meaning zero CPU usage).
|
|||
18 Dec 2006, 23:14 |
|
Tomasz Grysztar 18 Dec 2006, 23:46
Well, if you want just anything other than Sleep, you may try WaitForSingleObject (perhaps even combined with CreateWaitableTimer).
|
|||
18 Dec 2006, 23:46 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.