Search code examples
assemblytimedelayx86-16

How to set 1 second time delay at assembly language 8086


My problem is that I have written a code that is supposed to output a result into a set of LEDs connected to the parallel port. When I ran the code it pretty much did nothing. My instructor told me that the code ran too fast that my eyes did not see what happened.

I have found that there are a couple of ways to do a time delay, I have tried to loop the NOP but I think I cannot really determine what is going on. Is there any better way?

I have here a part of the code where I have to add a time delay into:

org 100h

mov ax, 0
mov dx, 378
out dx, ax
mov ax, 1  

; 1st

mov cx, 1ah
start1st:
mov ax, 1
left:
out dx, ax 
; --------------------------------> how to loop?
mov bx, 2
mul bx
cmp ax, 80h
jl left
dec cx
cmp cx,0
jg start1st
; end 1st 

Solution

  • What i finally ended up using was the nop loop

    ; start delay
    
    mov bp, 43690
    mov si, 43690
    delay2:
    dec bp
    nop
    jnz delay2
    dec si
    cmp si,0    
    jnz delay2
    ; end delay
    

    I used two registers which I set them both to any high value and its gonna keep on looping until both values go to zero

    What I used here was AAAA for both SI and BP, i ended up with roughly 1 second for each delay loop.

    Thanks for the help guys, and yes, we still use MS DOS for this assembly language course :(