Assembly language time delay


by abdo375
Tags: assembly, delay, language, time
abdo375
abdo375 is offline
#1
Jan7-07, 05:15 PM
P: 143
I need to write a program that will create a constant time delay in x86 assembly, can anybody help?
Phys.Org News Partner Engineering news on Phys.org
New ultrasound device may add in detecting risk for heart attack, stroke
Enhanced ground control system and software for small unmanned aircraft
SensaBubble: It's a bubble, but not as we know it (w/ video)
NoTime
NoTime is offline
#2
Jan7-07, 11:06 PM
Sci Advisor
HW Helper
P: 1,572
There are at least 3 ways to do this depending on just what you are trying to do.
Loop cycle count - high resolution but cpu dependent.

Or not cpu dependent.
Hardware clock byte fetch - with or without interrupt overlay about 100th second.

Bios timer interrupt - low resolution 18.7ms IIRC.

Any ideas on which one is more suitable?
abdo375
abdo375 is offline
#3
Jan8-07, 05:15 PM
P: 143
Hardware clock byte fetch and bios timer interrupt would be perfect, I'm trying to write an assembly code that would initialize an LCD so I need a delay of 200ms

abdo375
abdo375 is offline
#4
Jan8-07, 07:27 PM
P: 143

Assembly language time delay


btw is there a link on how to use any of them.
berkeman
berkeman is offline
#5
Jan8-07, 07:38 PM
Mentor
berkeman's Avatar
P: 39,723
Using the hardware timers and interrupts should be described in your x86 programmer's manual and the datasheet for the chip. Is it not there?
abdo375
abdo375 is offline
#6
Jan8-07, 07:43 PM
P: 143
actually I'm doing it on a PC.
berkeman
berkeman is offline
#7
Jan8-07, 07:46 PM
Mentor
berkeman's Avatar
P: 39,723
Quote Quote by abdo375 View Post
actually I'm doing it on a PC.
Oh, that's different. You're not going to get consistent timing on a PC running a non-real-time OS like Windows. The jitter is aweful due to the scheduling of tasks and interrupts from all over the place. If you want consistent timing with a PC, you'll need to make external hardware that makes the real-time waveform and timings, and then just do overall control and monitoring from the PC's jittery responses.

You can get real-time operating systems that you can run on the PC, and they'll probably have plenty of documentation on how to get consistent timings and execution.

You sure you want to do it on a Windows PC?
abdo375
abdo375 is offline
#8
Jan8-07, 08:11 PM
P: 143
berkeman, there seems to be a way but it's not working for me, the 5th bit of the 61h port toggles every 15us, which can be used for CPU-clock dependent time delay but like I said it's not working for me.

will it work on a non-multi-tasking operating system like DOS for example ?
berkeman
berkeman is offline
#9
Jan8-07, 08:41 PM
Mentor
berkeman's Avatar
P: 39,723
DOS is a good idea, but I think there are still interrupts from system functions (like keyboard and mice, etc.) that cause jitter. There are real-time OS available, but sorry, I'm not that familiar with them. I use uCs mostly, where I control the whole shebang.

I checked wikipedia.org, and they have a pretty good entry on real-time OS:

http://en.wikipedia.org/wiki/Real_time_operating_system
abdo375
abdo375 is offline
#10
Jan9-07, 01:42 PM
P: 143
thanks, berkeman.
mmox123
mmox123 is offline
#11
Jan15-10, 02:25 PM
P: 1
Quote Quote by abdo375 View Post
I need to write a program that will create a constant time delay in x86 assembly, can anybody help?
Typical Pentium software delay loops can be written using MOV and LOOP instructions.
For example, the following instruction sequence can be used for a delay loop: MOV CX,count DELAY: LOOP DELAY
The initial loop counter value of “count” can be calculated using the cycles required to execute the following Pentium instructions: MOV reg/imm (1 cycle) LOOP label (5/6 cycles)
Note that the Pentium LOOP instruction requires two different execution times. LOOP requires six cycles when the Pentium branches if the CX is not equal to zero after autodecrementing CX by 1. However, the Pentium goes to the next instruction and does not branch when CX = 0 after autodecrementing CX by 1, and this requires five cycles.
This means that the DELAY loop will require six cycles for (count - 1) times, and the last iteration will take five cycles.
For a 100-MHz Pentium clock, each cycle is 10 ns. For 2 ms, total cycles =2ms/10ns= 200,000. The loop will require six cycles for (count - 1) times when CX + 0, and five cycles will be required when no branch is taken (CX = 0). Thus, total cycles including the MOV = 1 + 6 x (count - 1) + 5 = 200,000. Hence, count = 33,333,0. Therefore, CX must be loaded with 33,33310


Register to reply

Related Discussions
Assembly Language Electrical Engineering 10
Assembly Language Engineering, Comp Sci, & Technology Homework 0
Assembly language Electrical Engineering 5
*****need help programing in assembly language***** Programming & Computer Science 1
Turbo Assembly Language Computing & Technology 2