How to set 1 second delay in assembler 8086

My problem is that I wrote code that should output the result to a set of LEDs connected to the parallel port. When I ran the code, it did almost nothing. My instructor told me that the code ran too fast, that my eyes did not see what happened.

I found that there are several ways to make a time delay, I tried to loop the NOP, but I think I can not determine what is happening. Is there a better way?

I have a piece of code where I have to add a time delay to:

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 
+8
source share
7 answers

What I finally ended up using a 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 to any high value and it will continue to cycle until both values ​​reach zero

What I used here was AAAA for both SI and BP , and for each delay cycle I got about 1 second.

Thanks for helping the guys, and yes, we are still using MS DOS for this assembly language course :(

+2
source

Set the interval to 1 million microseconds (1 second) using the instructions below.

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

You can set multiple delay with 86H and INT 15H

check these links for more details

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

INT 15H 86H: Wait

+10
source

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

So, to wait about 1 second using this method, you execute this interrupt function once, store CX: DX in a variable, then do the same interrupt in a loop until the absolute value of CX:DX - firstCX:DX 18.

+8
source

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

The example below holds about 1/4 of a second.

 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 
0
source
 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 
0
source
 delay proc near push bx puch cx mov bx,2 n1:mov cx,0 loop $ dec bx jnz n1 pop bx ret delay endp 
0
source
 .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 I'm in;)

-1
source

All Articles