We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,560 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Plz help me with this delay routine

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)

3
Contributors
3
Replies
1 Day
Discussion Span
1 Year Ago
Last Updated
4
Views
st_infamous
Newbie Poster
6 posts since Jun 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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

rubberman
Posting Maven
2,569 posts since Mar 2010
Reputation Points: 365
Solved Threads: 305
Skill Endorsements: 51

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

st_infamous
Newbie Poster
6 posts since Jun 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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.

GunnerInc
xor eax, eax
Team Colleague
90 posts since Jan 2011
Reputation Points: 38
Solved Threads: 13
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.1639 seconds using 2.74MB