Problem 2. Code Debugging (15 points) The subroutine below is broken. It is supp
ID: 3914743 • Letter: P
Question
Problem 2. Code Debugging (15 points) The subroutine below is broken. It is supposed to be a string length subroutine, but it never finishes. When it runs, it just loops forever. Fix it. icalculates length of null-terminated string 0 -pointer to string strlen: sub r18, r18, r18 addi r20, r0, 0 lar r21, out lar 22, loop ld 23, 0 (r20) brzr r21, r23 addi r18, rl8, 1 br addi r4, r18, 0 br r30 clear r18 imove arg to r20 get a pointer to out iget a pointer to loop load char from string quit if it is zero increment count loop to do it again put result in r4 adios loop: r22 out:Explanation / Answer
The code keeps comparing the first character of the string to zero hence it is infinite loop.
So you have to change the first instruction of the loop label to
ld r23,r18(r20)
then it will keep comparing subsequent characters in string
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.