Question: Modify the following program to ask for both a positive integer n greater than or equal to 3 and a character ch. Now have your

Modify the following program to ask for both a positive integer n greater than or equal to 3 and a character ch. Now have your program print an n-by-n hollow square of the character ch. For example, if user enters 3 and X; 4 and U, it would print the following:

Modify the following program to ask for both a positive integer n

The program will continue to ask for input and print output until n=0, then exit.

This is the code to be modified:

.data prompt: .asciiz "Enter a non-negative value for n: " newline: .asciiz " " asterisk: .byte '*' .text #prompt and read int li $v0, 4 la $a0, prompt syscall #read int and store in $t0 li $v0, 5 syscall move $t0, $v0 #store n in $t0 #print n li $v0, 1 move $a0, $t0 syscall #prompt newline li $v0, 4 la $a0, newline syscall li $t1, 1 #counter loop: bgt $t1, $t0, end_loop #print asterisk\ li $v0, 11 lb $a0, asterisk syscall add $t1, $t1, 1 #increment counter b loop end_loop: #exit li $v0, 10 syscall

output

-----

Enter a non-negative value for n: 5 5 ***** -- program is finished running -- Enter a non-negative value for n: 2 2 ** -- program is finished running -- Enter a non-negative value for n: 0 0 -- program is finished running --

3 4

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 Databases Questions!