Question
I have the following MIPS(MARS 4.5) code: .data prompt: .asciiz Enter an N value: prompt1: .asciiz Enter a character: newline: .asciiz
I have the following MIPS(MARS 4.5) code:
.data
prompt:
.asciiz "Enter an N value: "
prompt1:
.asciiz "Enter a character: "
newline:
.asciiz " "
n: .word 0
answer: .word 0
errormsg:
.asciiz "N should be greater or equal to 3"
userInput: .space 2
space: .asciiz " "
.text
.globl main
main:
#prompt1 and read character
li $v0, 4
la $a0, prompt1
syscall
#Getting user's input as text
li $v0, 8
la $a0, userInput
li $a1, 2
syscall
#prompt newline
li $v0, 4
la $a0, newline
syscall
#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
bge $v0, 3, proceed #if input is 0 or more, goto proceed otherwise display error message and goto exit
li $v0, 4
la $a0, errormsg
syscall
b exit
proceed:
#print n
li $v0, 1
move $a0, $t0
syscall
#prompt newline
li $v0, 4
la $a0, newline
syscall
loop1:
beq $t3, $t0 exit
addi $t3, $t3, 1 # Increment counter
li $t4, 0
######################## Inner loop
loop2:
beq $t4, $t0 end_loop2
addi $t4, $t4, 1 # Increment counter
li $t1,1
bne $t3,$t1, IF # i==1
bne $t3,$t0, IF # i==N
bne $t4,$t1, IF # j==1
bne $t4,$t0, IF # j==N
IF:
li $v0, 4
la $a0, userInput
syscall
b loop2
ELSE:
li $v0, 4
la $a0, space
syscall
b loop2
end_loop2:
#prompt newline
li $v0, 4
la $a0, newline
syscall
b loop1
exit:
li $v0, 10
syscall
.end main
#######################
What I want to accomplish with this code is a hallow square
The OUTPUT im getting is the following:
3 XXX XXX XXX
THE OUTPUT I SHOLD BE GETTING ARE THE FOLLOWING:
*C program to print hollow square star pattern #includeStep 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