Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

The OUTPUT im getting is the following:

3 XXX XXX XXX

THE OUTPUT I SHOLD BE GETTING ARE THE FOLLOWING:

image text in transcribed

*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

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

Flash XML Applications Use AS2 And AS3 To Create Photo Galleries Menus And Databases

Authors: Joachim Schnier

1st Edition

0240809173, 978-0240809175

More Books

Students also viewed these Databases questions

Question

List out some inventory management techniques.

Answered: 1 week ago

Question

What do Dimensions represent in OLAP Cubes?

Answered: 1 week ago