News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Waiting between operations

Started by Yarui, December 17, 2009, 03:09:46 AM

Previous topic - Next topic

Yarui

I am just finishing an assembly language class and our last homework assignment was to make a program that draws boxes in a command window. I have already finished the assignment, but I just had an urge to take it a little further.  I basically click on the .exe file and it brings up a window that has the final product drawn instantly, and it got me wondering what it would take to make the program wait between each operation so that you can actually see the boxes being drawn. The program basically just uses a gotoxy function to go to the coordinates of each corner and side, and writes the characters, so my thought is that if you made the program wait about 1/10 of a second between each call to the WriteChar function, it would make it look like the boxes are being drawn in real time.  I looked around for discussion on how to make a program wait a set amount of time with little luck.  I found that there is a wait instruction, but haven't been able to figure out what it does or how to use it.  Could anyone offer me some ideas?

Edit: It just occurred to me that Gotoxy and WriteChar are both functions from Kip Irvine's ASM library and I have been a little curious for a while if that library is considered to be fairly standard or if it is just for learning.  Would I be better off avoiding the use of that library in the future so that I can get a better understanding of the use of the standard masm32 library?

dedndave

well - the wait instruction is for something else entirely
it forces the CPU to wait for the FPU to complete the current operation
it can be used to wait for an external piece of hardware, like a craphics co-processor or something
it is rarely used that way, and is hardware dependant, of course

i take it you are writing 32-bit code
a simple delay can be obtained from the Sleep API function
a one second delay....

        INVOKE  Sleep,1000

the nice thing about Sleep is, the OS uses the CPU time to perform other tasks
the bad thing about it is, it is a bit jittery (noticable for short delays), as the OS synch's it with time-slices

more precise delays can be had using QueryPerformanceCounter, or even the RDTSC instruction

EDIT- the last 2 are clock-dependant - so you may want to measure the count:time duration

another way to go is to use one of the time-of-day functions - probably best for what you want
the delay would be the same time-period on any machine, that way
i suggest GetSystemTimeAsFileTime
http://msdn.microsoft.com/en-us/library/ms724397(VS.85).aspx

i might be inclined to use Sleep,75 to consume most of the wait period
then, use GetSystemTimeAsFileTime to find the end of the period for repeatability

Yarui

I tried adding the invoke sleep line before every occurrence of call WriteChar and it didn't work out quite the way I was hoping.  Do you know if that changes the values in any of the registers? The program doesn't really work at all anymore and I think it may be because one of the registers I was using to go to a location has been changed by the sleep function.  I will try out those other functions you mentioned sometime too.  My main purpose of doing this is just learning to use some more functions that I don't already know, so I'll try to get it working both ways.

Edit: The first place it seemed to be getting hung up was in the loop I was using to draw the sides, so I tried to do it by just waiting after drawing each corner, it worked slightly better, but the position of the lines was all wrong, so I figured sleep uses the edx, since the gotoxy function uses the dl and dh.  So I pushed the edx before using sleep then popped it afterwards and everything was in the right spot after that, but only the first corner was there, the other 3 were blank.  Since the character that is to be drawn is stored in the al register I pushed the EAX onto the stack too and after I did that it draws them all right.... it would probably be better to just restore the al each time since the character is stored in memory anyway, it just seemed like the fastest way to test it out.

dedndave

show us your code - you may want to zip it and attach it
below the reply window is a hyper-link called "Additional Options..."
click on that to attach files

the API functions are free to use eax, ecx, and edx registers
most of them return a status in eax

Yarui

Yeah, the EAX and the EDX seem to be what was causing the problems, it is working the way I was hoping now.  I could probably rewrite it in a way that is tailored a little better to doing this now.  Thanks a lot for your help.