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:
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 4Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started