Question: 2 ) A colleague decided that the PrintInt subprogram should print a new line after the integer has been printed and has modified the PrintInt

2) A colleague decided that the PrintInt subprogram should print a new line after the integer has been printed and has modified the PrintInt to print a new line character as follows.
(Note: PrintNewLine subprogram is described in Chapter 5 of your textbook.)
# subprogram: PrintInt
# author: Charles W. Kann
# purpose: To print a string to the console
# input: $a0- The address of the string to print.
# $a1- The value of the int to print
# returns: None
# side effects: The String is printed followed by the integer
value.
.text
PrintInt:
# Print string. The string address is already in $a0
li $v0,4
syscall
# Print integer. The integer value is in $a1, and must
# be first moved to $a0.
move $a0, $a1
li $v0,1
syscall
# Print a new line character
jal PrintNewLine
#return
jr $ra
When the program is run, it never ends and acts like it is stuck in an infinite loop. Help this colleague figure out what is wrong with the program.
a. Explain what is happening in the program that makes it an infinite loop.
b. Document a solution which fixes this problem so that PrintInt prints the integer and a newline, and then returns to the point in which was called without creating and infinite loop.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!