Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delay/Sleep in assembly???

Status
Not open for further replies.

s4shif

Programmer
Nov 7, 2003
1
0
0
DK
hello

I am looking for any function/interrupt which can serve the purpose of sleep/delay in an assembly language program,

(as we use sleep() fuction in C language)

Looking for an early response...

s4shif
 
Hi s4shif!

Look at Ralf Brown's Interrupt List:(INT 15,86 - WAIT)
------------------------------------------------------------
INT 15 - BIOS - WAIT (AT,PS)
AH = 86h
CX:DX = interval in microseconds
Return: CF clear if successful (wait interval elapsed)
CF set on error or AH=83h wait already in progress
AH = status (see #0422)
Note: the resolution of the wait period is 977 microseconds on many systems
because many BIOSes use the 1/1024 second fast interrupt from the AT
real-time clock chip which is available on INT 70; because newer
BIOSes may have much more precise timers available, it is not
possible to use this function accurately for very short delays unless
the precise behavior of the BIOS is known (or found through testing)
------------------------------------------------------------

Best Wishes...
OSProgrammer
 
If you don't want to use interrupts, you can get second count from the CMOS. I wrote a program to show what I mean. It works, but the value in cx is about double the time in seconds.
Code:
assume cs:code

code segment
  org 100h
program:
  jmp start

  sec db ?

start:

  mov cx,0030h
  call timer

  mov ax,4c00h
  int 21h


; input: cx is value to delay for.
;        (approximate to seconds).
timer:
  sub bx,bx

  mov al,00h ; seconds address
  out 70h,al ; wake up port
  jmp $+2    ; a short delay
  in al,71h
  mov [sec],al

timer_loop:
  mov al,00h ; seconds address
  out 70h,al ; wake up port
  jmp $+2    ; a short delay
  in al,71h
  cmp al,[sec]
  je timer_loop
  ; second gone by...
  mov [sec],al
  inc bx
  cmp bx,cx
  jne timer_loop
  ret

code ends

end program
:)


The mind is like a parachute - it works better when open...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top