title: How can I create a sleep function in 16bit MASM Assembly x86?
body: <p>I am trying to create a sleep/delay procedure in 16bit MASM Assembly x86 that will, say, print a character on the screen every 500ms.
  From the research I have done, it seems that there are three methods to achieve this - I would like to use the one that uses CPU clock ticks.</p>
  
  <p>Please note I am running Windows XP through VMWare Fusion on Mac OS X Snow Leopard - I am not sure if that affects anything.</p>
  
  <p>Could someone please point me in the right direction, or provide a working piece of code I can tweak? Thank you!</p>
  
  <p>The code I have found is supposed to print 'A' on the screen every second, but does not work (I'd like to use milliseconds anyways).</p>
  
  <pre><code>TOP:
  MOV AH,2C
  INT 21
  MOV BH,DH  ; DH has current second
  GETSEC:      ; Loops until the current second is not equal to the last, in BH
  MOV AH,2C
  INT 21
  CMP BH,DH  ; Here is the comparison to exit the loop and print 'A'
  JNE PRINTA
  JMP GETSEC
  PRINTA:
  MOV AH,02
  MOV DL,41
  INT 21
  JMP TOP
  </code></pre>
  
  <p><strong>EDIT: Following GJ's advice, here's a working procedure. Just call it</strong></p>
  
  <pre><code>DELAY PROC
   TIMER:
   MOV     AH, 00H
   INT     1AH
   CMP     DX,WAIT_TIME
   JB      TIMER
   ADD     DX,3         ;1-18, where smaller is faster and 18 is close to 1 second
   MOV     WAIT_TIME,DX
   RET
  DELAY ENDP
  </code></pre>