Sunday, September 13, 2009

Debug the delay routine (8085)

Statement:The delay routine given below is in infinite loop, identify the error and correct the program.

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

No comments:

Post a Comment