Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students also viewed these Databases questions

Question

Trudy, when she first saw the bull pawing the ground, ran.

Answered: 1 week ago