Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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 #include int main( int i, j, N; Input number of rows from user/ printf("Enter number of rows: "); scanf("%d", &N); Iterate over each row /*Iterate over each column/ for (j-1; j

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_2

Step: 3

blur-text-image_3

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

Concepts of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

7th edition

978-1111825911, 1111825912, 978-1133684374, 1133684378, 978-111182591

More Books

Students also viewed these Databases questions

Question

What causes musculoskeletal pain? LO.1

Answered: 1 week ago

Question

How long does it take you to get ready in the morning?

Answered: 1 week ago