Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

.data prompt: .asciiz \"Enter the value of n \ \" #message to user stored as str

ID: 667531 • Letter: #

Question

.data

prompt: .asciiz "Enter the value of n " #message to user stored as string

num: .space 4 #space of 4 bytes reserved for inputting the value of n entered by user

.text

main:

la $a0, prompt #address of prompt stored in argument register to print

li $v0, 4 #4 is the service code to print string

syscall #call to system made to print string

li $v0, 5 #5 is the service code to read int

syscall #call to system made to read int

sw $v0, num #number input by user stored in variable num

j allcols #jump to label allcols

spaceloop:

li $t0, 0 #counter for this loop

spaceloop1:

lb $a0, sp #load space in argument register

li $v0, 11 #11 is the service code to print character stored in a0

syscall #call to system made to print character

addi $t0, $t0, 1 #counter of this loop incremented

blt $t0, num, spaceloop1 #condition check for this loop

jr $t1 #ra #jump back to the caller

allcols:

li $t6, 0 #this is the main counter. for every value of this counter, one column of characters and

#one column of spaces are printed

li $t7, 65 #65 is the ASCII value of A

addi $t7, $t7, num #this represents the largest character which can be printed

allcols1:

addi $t1, $t6, 65 #this stores the ASCII value of first character of column in the register t1

onecol:

li $t0, 0 #t0 is the counter variable for this inner loop which prints one column of characters and spaces

onecol1:

blt $t1, $t7, unmod #this is for checking if t1 has gone beyond the largest character

sub $t1, $t1, num #if t1 is greater than largest character, it has to be brought back to A

unmod:

lb $t1,-100($t2) #ASCII value of character in t1 is stored in argument register

li $v0, 11 #11 is the service code to print character

syscall #call to system made to print character

addi $t0, $t0, 1 #counter of inner loop incremented

addi $t1, $t1, 1 #character to be printed incremented

blt $t0, num, onecol1 #condition check for inner loop

jal spaceloop #jump to label spaceloop, print a column of spaces and return back to the next line

addi $t6, $t6, 1 #main counter incremented

blt $t6, 6, allcols1 #condition check for main counter - outer loop

li $v0, 10 #10 is the service code to terminate program

syscall #call to system made to terminate program

. What to do: Write a MIPS program to print out a matrix of pattern, based on the user's input n. »Levels of completion: #: 26 / 50 Level 1 example (n=5) Level 3a) example (n=5) Level 2 example (n-7) Level 1: Passing grade (8o/100): Take a number n from the user, print out a matrix (2n columns, n rows) of the above pattern (starting with character 'a') Level 2: Full grade (100/100): Take a number n from the user (assuming the user always inputs an odd number for n), print out a matrix as level 1, but with a "diamond of *" in the middle of it

Explanation / Answer

newline: .asciiz " " # g .text main: addi $v0, $zero, 4 la $a0, str1 syscall addi $v0, $zero, 5 syscall add $s0, $zero, $v0 addi $v0, $zero, 4 la $a0, str2 syscall addi $v0, $zero, 5 syscall add $s1, $zero, $v0 L1: beq $s1, $zero, cont addi $v0, $zero, 1 add $a0, $s0, $zero addi $s1, $s1, -1 syscall j L1 cont: addi $v0, $zero, 4 la $a0, newline syscall addi $v0, $zero, 10 syscall jr $ra