Statement:The delay routine given below is in infinite loop, identify the error and correct the program.
Home
8085 Forum
8085 Free Projects
8085 Free Programs
8085 Tutorials
8085 details
Interfacing Techniques
Electronic Tutorials
Electronic Projects
Assembler/ IDE
Datasheets
Guest Book
About Me
Delay routine with error:

       DELAY  : LXI H, N        
       L1         : DCX H
                 JNZ L1

Sol.: 1) The fault in the above program is at instruction JNZ L1. This condition always evaluates to be true hence loops keep on executing and hence infinite loop.

2) Reason for infinite looping: - The instruction DCX H decrease the HL pair count one by one but it does not affect the zero flag. So when count reaches to OOOOH in HL pair zero flag is not affected and JNZ L1 evaluates to be true and loop continues. Now HL again decrements below OOOOH and HL becomes FFFFH and thus execution continues.

3) The modification in the program is as follows:
       
       DELAY    :  LXI H, N                :Load 16 bit count
       L1            :   DCX H                : Decrement count
                    MOV A, L                   
                   ORA H             : logically OR Hand L
                   JNZ L1                : If result is not 0 repeat