do question number 2 and show answer step by step ulls and Uplate necessary poin
ID: 3878376 • Letter: D
Question
do question number 2 and show answer step by step
Explanation / Answer
Problems with the above code are:-
1. The Loop structure (LOOP_) is an infinite loop as it doesnt have any terminating condition that states when the loop should terminate. Here we have just a start of the loop (LOOP_) and an end loop statement(ENDLOOP_) . How do we know when the loop will eventually terminate if the inside if condition (IF_INTCON, INT01F ==1) holds true always and we have CONTINUE statement which will revert back control to the start of the loop again and again. The loop will execute indefinitely.
2. Inside the if condition (IF_INTCON, INT01F ==1), we are calling a subroutine LoopTime (rcall LoopTime). Each call to a subroutine gets placed on a stack memory and when it returns control to the caller its popped from the stack. If we call it 3 times means its pushed into the stack memory 3 times and the Loop itself is infinite which means there are changes of StackOverflowException i.e We can run out of Stack Memory which is very limited.
3. Placing break statement outside the IF condition results in unwanted/premature termination of the loop when the IF evaluates to false. Say if the IF condition is not equal to 1 the Loop terminates because of BREAK_ statement, without checking or executing any other statements within the LOOP_.
Corrections required for Smooth Execution:-
1. Loop should have a terminating condition so that it terminates eventually and doesnt run indefinitely.
2. Call a subprogram inside a loop minimal times as operations of Stack memory is very limited and precious. Keep the common code part inside that subprogram and call once. This will reduce chances of StackOverflow error.
3. Use BREAK_Statements inside IF_ Conditions so that only on evaluation of an expression the loop is terminated, not forcibly or prematurely or errorneously.
4. Place constant statements outside the loop (bsf PORT A,2) as it performs the same operation repeatedly without having any effect of the loop. This improves execution time of the Sub-Program.
Please let me know in case of any clarifications required. Thanks!
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.