Question
Help with MIPS assembly language (MARS 4.5) hallow square base on N input This is what I have so far, can someone help me please
Help with MIPS assembly language (MARS 4.5) hallow square base on N input
This is what I have so far, can someone help me please What I need help with is with the if statement so that I will print the character a user inputs The expected output for the program is the following:
3
XXX
X X
XXX
MY CODE: so far
.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
for1:
beq $t3, $t0, end_for1
addi $t3, $t3, 1 # Increment counter
li $t4, 0 #reseting j to 0 after each iteration of the for loop
######################## Inner loop
for2:
beq $t4, $t0, end_for2
addi $t4, $t4, 1 # Increment counter
beqz $t4, if
b for2
if:
#print Character
li $v0, 4
la $a0, userInput
syscall
end_if:
end_for2:
######################## Inner loop
b for1
end_for1:
exit:
li $v0, 10
syscall
.end main
*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