Computing.Net > Forums > Programming > delay in asm

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

delay in asm

Reply to Message Icon

Name: wtk
Date: December 5, 2003 at 17:17:00 Pacific
OS: WinNT
CPU/Ram: ???
Comment:

hello,

does anyone know how to make a "delay", say 0.5 second, in assembly language? i am using a x86 processor, window NT, and the program compiled with turbo assembler 6.0. thanks.

wtk :)



Sponsored Link
Ads by Google

Response Number 1
Name: wtk
Date: December 5, 2003 at 17:23:28 Pacific
Reply:

btw, i would like to know actually how many people out there are still learning assembly language. well, i mean *just* learning, not actually coding in assembly? i find asm is lot of fun. :)

wtk


0

Response Number 2
Name: SN
Date: December 5, 2003 at 20:02:40 Pacific
Reply:

On the motorola processors, there are timer output compare registers which can be used to create a delay that is not clock speed-dependent. Basically you read in a clock, add a delay to its value, and set a timer output compare register to set a flag when the two are equal. You read this flag until it is set, then you can move on. You may need to wait until it is set and reset several times to get a .5sec delay. My guess is that intel has something similar.

This method is reasonably complex and requires a basic understanding of the architecture...My guess is that you can probably find asm packages or something that have a subroutine that does this.

To answer the "learning" question, Probably around 4-6 of my classes have dealt with assembly on some level, some very heavily, some only with respect to architecture design.

Good luck,
-SN


0

Response Number 3
Name: anonproxy
Date: December 5, 2003 at 22:45:13 Pacific
Reply:

Delays are actually very important in logic components - they are common. You want a timing delay loop, but you don't want to calculate it according to your processor's clock speed. This is something like an EE would figure out (because obviously they are dealing with a specific system in a given state, not necessarily generic software). Instead, you have to use a timer - as was mentioned above.

This thread explains a timer in x86 assembly.


0

Response Number 4
Name: JackG
Date: December 6, 2003 at 00:55:40 Pacific
Reply:

If you were running under DOS instead of a protected mode OS, then there is a simple way to do a fixed timing loop that works for up to almost one second. The problem is that with protected mode OS's you can be interrupted out of any timing loop for long periods of time. The only way to do this is to make OS system API calls that return control back to you after the specified timeout. These are basic OS API function calls in windows used by VXD and Device drivers.


0

Response Number 5
Name: Mohamed
Date: December 8, 2003 at 12:59:41 Pacific
Reply:

the following proc. will provide you with a delay of 10 micro-sec.
;;;;;;;;;;;;;;;;;;;;;;;;;;;
DELAY proc near
mov bx,64h
w_1: mov cx,03e7h
w_10: nop
loop w_10
dec bx
cmp bx,00h
jne w_1
ret
delay endp


0

Related Posts

See More



Response Number 6
Name: SN
Date: December 8, 2003 at 13:45:14 Pacific
Reply:

As I've mentioned, I'm only familiar with the syntax of old school motorola assembly, but I'm guessing that the above loop makes two rather large assumptions:

1. That a NOP operation takes a certain amount of time...1 ns I think? This is clock-speed and processor dependent, so it's probably not a great assumption to make if accuracy is important.

2. That no interrupts will occur during the loop. Jack touched on this...Basically the OS can interrupt your program whenever it dang well feels like it and do its thing, then return control back to your program. So if you're just writing a loop of NOPs then there's no guarantee that you get exactly (or even close to) the right time delay.

Use a timer. It's more complex, but it works.

-SN


0

Response Number 7
Name: myxp
Date: December 8, 2003 at 15:33:20 Pacific
Reply:

SN is right. Use of a chipset based timer is the ultimate solution since the output pulses depend on the frequency of the system timer divided with 2^n (base 2 raised to the power of n, n being the binary resolution).

Part of the clock generated frequency is divided down by the chipset to a fixed frequency fed into the system timer.

Since the system timer frequency is fixed, the number of output pulses from the timer only depended on the binary value written to the timer to output a pulse for every 2^n counts.


MYXP


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: delay in asm

Using Bios int functions in ASM www.computing.net/answers/programming/using-bios-int-functions-in-asm/3392.html

Loading bmp's in asm www.computing.net/answers/programming/loading-bmps-in-asm/3143.html

symbol type conflict in asm Win XP www.computing.net/answers/programming/symbol-type-conflict-in-asm-win-xp/897.html