flat assembler
Message board for the users of flat assembler.

Index > Windows > [help] Coding a sleep-delay function without API

Author
Thread Post new topic Reply to topic
XY2k



Joined: 18 Feb 2006
Posts: 6
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
Post 14 Dec 2006, 15:15
View user's profile Send private message Reply with quote
coconut



Joined: 02 Apr 2004
Posts: 326
Location: US
coconut 14 Dec 2006, 16:12
i remember my old vb6 days, i did something like
Code:
sub pause(seconds as integer)

x = timer()
do:doevents
loop until timer-x=seconds

end sub
    


im not sure if you can translate that to fasm, without using an api to get current time
Post 14 Dec 2006, 16:12
View user's profile Send private message Reply with quote
Plue



Joined: 15 Dec 2005
Posts: 151
Plue 14 Dec 2006, 16:45
Basically you can't if you don't have access to the timer interrupt or the api.
Post 14 Dec 2006, 16:45
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8039
Location: Kraków, Poland
Tomasz Grysztar 14 Dec 2006, 17:28
Well, if you know what clock your processor has, you may try the RDTSC.
Post 14 Dec 2006, 17:28
View user's profile Send private message Visit poster's website Reply with quote
Plue



Joined: 15 Dec 2005
Posts: 151
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 Wink

Waiting for five seconds <> looping for five seconds.
Post 14 Dec 2006, 20:46
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8039
Location: Kraków, Poland
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).
Post 14 Dec 2006, 22:34
View user's profile Send private message Visit poster's website Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
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.
Post 14 Dec 2006, 23:38
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
XY2k



Joined: 18 Feb 2006
Posts: 6
XY2k 18 Dec 2006, 14:45
Sorry guys and thx for answers Smile,
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 Sad

I´m happy when somebody can give me a peace of code Smile

regards,
XY2k
Post 18 Dec 2006, 14:45
View user's profile Send private message Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak 18 Dec 2006, 21:21
Well, if some one gives you the code how can you recode it yourself?
Post 18 Dec 2006, 21:21
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
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).
Post 18 Dec 2006, 23:14
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8039
Location: Kraków, Poland
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).
Post 18 Dec 2006, 23:46
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.