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)

I don't suppose you have tried building this debuggable, and they tried running it in a debugger?

i'm sry but i'm unfamiliar to using debuggers

2 things:
1. All of this code:

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

HAS TO BE in your code section NOT the data section!!!!
2. Use the Sleep or SleepEx API

also, you cannot use privilaged instructions in user mode. IN is a privilaged instruction.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.