Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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

ulls and Uplate necessary pointers and ill contents explain) and discuss in detail along with of RAM or program 2. Please read the following sequence of commands (code) i LoPrilSR ing sequence of commands (code) in the subroutine 10points) LoPrilSR 10points) LOOP IF INTCON,INTOIF-= 1 rcall LoopTime rcall LoopTime rcall LoopTime bsf PORTA,2 - CONTINUE ENDIF BREAK ENDLOO retfie Please explain in detail what is the problem with the above code explanation should explain clearly why the above code will create problems, what those problems will be and what is the correction to ensure smooth operation of the program that contains the above subroutine. Note that the Interrupt Handler is not written as a separate routine, like it was given in class, but rather incorporated above and that should NOT be a problem a) Assume that an external hard storage. How many memory location contains 1 byte as always? drive has 3 Tbytes of available memory for 5 points) 3. bits are needed for addressing its memory assuming each

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!