For different computers, because their main frequency is different, the parameters of delay 1s are also different. The method of calculating delay is as follows:
Computer frequency: x (Hz)
The number of cycles of execution of a LOOP statement: y
The time required for delay: z (s)
Number of statements to be executed: a
z=y*(1/x)*a
Calculate the required number of execution statements to write the program.
Example: (The main frequency of the computer is 3GHz)
delay proc near push bx push cx mov bx,400h for1:mov cx,0ffffh for2:loop for2 dec bx jnz for1 pop cx pop bx ret delay endp
Extended knowledge:
Single-chip assembly jump instruction delays by one second
DELAY: MOV R7,#10 ;Delay 1S subroutine
DL1: MOV R6,#200-----1T
DL2: MOV R5,#248------1T
DJNZ R5,$
DJNZ R6,DL2
DJNZ R7,DL1
RETLP
RET
How does this delay? The crystal oscillator is 12MHZ and T=1us, DJNZ is a double-period instruction. It mainly delays the nested loop for one second. Let's look at the calculation result:
DJNZ R5,$-----------------------248*2=496500us
DJNZ R6,DL2----------------------(496+1+2)*200=99800us
DJNZ R7,DL1------------------------(99800+2+1)*10=998030~~1s;
Summarize
The above is the implementation method of assembly language software delay 1s introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support for my website!
If you think this article is helpful to you, please reprint it. Please indicate the source, thank you!