Why do we need an infinite loop at the end of the program? Setup clr.w R4 ;clear
ID: 3849486 • Letter: W
Question
Why do we need an infinite loop at the end of the program?
Setup clr.w R4 ;clear all old registers from
clr.w R5 clr.w R6
clr.w R7 clr.w R10
mov.w #04, R4 ;set up registered values
mov.w #05, R5
mov.w #07,
R6 mov.w #15,R10
Addition mov.w R4, R7 ;add R4 to R7 = 4
add.w R5, R7 ;add R5 to R7 = 9
add.w R6, R7 ; add R6 to R7 = 16
Subtraction sub.w R10, R7 ; subtract R10 from R7 = 1
Store mov.w R4, &0200h
mov.w R5, &0202h
mov.w R6, &0204h
mov.w R10, &0206h
mov.w R7, &0208h
Mainloop jmp Mainloop ; Infinite Loop
Explanation / Answer
Once the code is executed completely, the processor or microcontroller has nothing to do and will be idle. So to make it busy with some work, we put an infinite loop at the end.
This infinite loop will tell the processor to stay at that line forever.
This is common practice for the functions which do not return a particular value to end the program.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.