How to set 1 second time delay at assembly language 8086

北城余情 提交于 2019-11-27 15:10:36

Set 1 million microseconds interval (1 second) By using below instruction .

MOV     CX, 0FH
MOV     DX, 4240H
MOV     AH, 86H
INT     15H

You can set multiple second delay by using 86H and INT 15H

check these links for more details

Waits a specified number of microseconds before returning control to the caller

INT 15H 86H: Wait

Michael

You can use interrupt 1Ah / function 00h (GET SYSTEM TIME) to get the number of clock ticks (18.2/s) since midnight in CX:DX.

So to wait approximately 1 second using this method you'd execute this interrupt function once, save CX:DX in a variable, then execute the same interrupt in a loop until the absolute value of CX:DX - firstCX:DX is greater than 18.

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 :(

Alfred Benigno

Alternatively, you can create a process and call it every time you want to delay using only the counter register and stack implementation.

Example below delays roughly 1/4 a sec.

delay       proc
            mov     cx, 003H
    delRep: push    cx
            mov     cx, 0D090H
    delDec: dec     cx
            jnz     delDec
            pop     cx
            dec     cx
            jnz     delRep
            ret
delay       endp
maks nosov
.DATA TIK DW ?
...
MOV AX,00H
INT 1AH

MOV TIK,DX
ADD TIK, 12H

DELAY:
MOV AX,00H
INT 1AH
CMP TIK, DX
JGE DELAY

I'm from mobile. Sorry for my enters ;)

delay proc near 
push bx
puch cx
mov bx,2
n1:mov cx,0
loop $
dec bx
jnz n1
pop bx
ret
delay endp
kinAfro
DELAY_1SEC: MOV R3,#0AH;10D
LOOP1:      MOV R2,#64H;100D
LOOP2:      MOV R1,#0FAH;250D
LOOP3:      NOP
            NOP
            DJNZ R1,LOOP3;4x250Dx1,085us=1,085ms (0s.001ms010)/cycle
            DJNZ R2,LOOP2;3x100Dx1,085ms=325,5ms (0s.100ms309)/cycle
            DJNZ R3,LOOP1;3x10Dx325,5us=976,5ms (1s.604ms856)/cycle
            RET
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!