I got this delay routine while searching the internet for ways to introduce a time delay (4-5 sec) in my assembly program. I fed it into a HelloWorld program to display 'Helloworld' box message after 10 sec from the execution of the program.
Here's the code
.386 .model flat, stdcall option casemap :none extrn MessageBoxA : PROC extrn ExitProcess : PROC .data HelloWorld db "Hello There!", 0 ; Delay routine FullVertWait: mov dx,3dah vr: in al,dx test al,8 jnz vr ; wait until Vertical Retrace starts nvr: in al,dx test al,8 jz nvr ; wait until Vertical Retrace Ends add word[count1],1 add eax,0 ret Delay: mov word[count1],0 ddf: call FullVertWait cmp word [count1],700 ; 70 = 1 second,so this = 10 seconds jne ddf ret count1 dw 0 ; End of delay .code start: call Delay lea eax, HelloWorld mov ebx, 0 push ebx push eax push eax push ebx call MessageBoxA push ebx call ExitProcess end start
However, this program crashes on execution. Can anyone help me out. Or is there any other simpler way by which i could introduce the delay?
(Using TASM to compile the code)