Question
Modify the MIPS program below to ask for both a positive integer n greater then or equal to 3 and a character ch. Now have
Modify the MIPS program below to ask for both a positive integer n greater then 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 the user entered 3 and X; 4 and U respectfully, it would print the following. Your program is to continue to ask for input and print the output until n=0, which will exit the program.
This program asks for a non-negative integer n, and prints the number as asterisks. 3 = ***, 5 = *****, etc.
.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
3xx 4UUUStep 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