la $t8, array#loads array pointer5859addi $t2, $t2, -4add $t1, $t3, 060#moves values from $t3 into $t16162j reverse6364reverse:65lw $t7, ($t2)lw $t9, $t8)Sw $t7, ($t8)sw $t9, ($t2)#loading the array($t2 into $t7)#loadibg the array($t8 into $t9)#stores into array#stores into array66676970add $t2, $t2, -4add $t8, $t8, 4bge $t8, $t2, print#decrements the array, taking number from tail#incremens the array, putting into the head717274j reverse757677 print883RRSRSRSE.

Question
Asked Oct 12, 2019
18 views

This is my code for an MIPS assignment where im taking numbers into an array and reversing within the array (I.E not creating another array)

.data
 
str1: .asciiz "Enter size of the array: "
str2: .asciiz "Error! The array element must be divisble by 3. "
str3: .asciiz "Error! The size of the array must be postive. "
str4: .asciiz "Error! the elements of array must be postive. "
str5: .asciiz "Error! The size of the array must be less than 20. "
str6: .asciiz "Error! The size of the array must be greater than 0. "
str7: .asciiz "The elements in array in reversed order is as follows:\n "
str8: .asciiz " " 
str9: .asciiz "Enter a element for the array: "
array:  .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
 
.text
main:
arraysize:
li $v0, 4
la $a0, str1#prompts user for size of array
syscall
 
li $v0, 5#takes user input for size of array
syscall
add $t0, $v0, $0#moves the user's value from $v0 to $t0
 
li $t9, 20#loads 20 into $t9
 
bgt $t0, $t9, err1#if greater than 20, goes to err1
ble $t0, $0, err2#if less than 0, goes to err2
add $t3, $t0, $0#move  values into $t1
 
 
la $t2, array#Loads array pointer
j creatArray
 
creatArray:
 
li $v0, 4
la $a0, str9
syscall
 
li $v0, 5#takes user's element to fill array
syscall
 
add $t1, $v0, 0 #moves $v0 into $t1
 
blt $t1, 0, negative #checks if element is negative, goes to negative
 
li $t8, 3#loads 3 into $t5, will be used to check divibility
div $t1, $t8#divides $t1 by $t8
mfhi $t8#stores remainder if there is
bne $t8, 0, notdiv#if there is remainder greater than 0, its not divible by 3
 
addi $t0, $t0, -1
sw $t1, 0($t2)#stores $t1 into the array
add $t2, $t2, 4#increments the array by 4 bytes
bgt $t0, 0, creatArray
 
la $t8, array#loads array pointer
 
addi $t2, $t2, -4
add $t1, $t3, 0#moves values from $t3 into $t1
j reverse
 
reverse:
 
lw $t7,($t2)#loading the array($t2 into $t7)
lw $t9,($t8)#loadibg the array($t8 into $t9)
sw $t7,($t8)#stores into array
sw $t9,($t2)#stores into array
 
add $t2, $t2, -4#decrements the array, taking number from tail
add $t8, $t8, 4#incremens the array, putting into the head
bge $t8,$t2, print
 
j reverse
 
print:
 
la $t2, array#loads array
 
li $v0, 4
la $a0, str7#prompts string
syscall
 
printArray:
 
lw $t5, ($t2)#loads #$t2 into $t5
li $v0, 1
add $a0, $t5, $0#moves $t5 into $a0 and prints
syscall
 
li $v0, 4
la $a0, str8#prompts a space
syscall 
 
add $t1, $t1, -1#increment
add $t2, $t2, 4#incement
bgt $t1, 0, printArray#prints array until empty
 
exit:
li $v0, 10#terminates program
syscall
 
err1:
 
li $v0, 4
la $a0, str5#prompts error
syscall
 
j arraysize#loops back to arraysize
 
err2:
 
li $v0, 4
la $a0, str6#prompts error
syscall
 
j arraysize#loops back to arraysize
 
negative:
 
li $v0, 4
la $a0, str4
syscall
 
j creatArray
 
notdiv:
 
li $v0, 4
la $a0, str2 
syscall
 
j creatArray

 

-----------------------------

in the attached image is the reversing part... can someone explain in detail what exactly or how it is exactly reversing 

 

la $t8, array
#loads array pointer
58
59
addi $t2, $t2, -4
add $t1, $t3, 0
60
#moves values from $t3 into $t1
61
62
j reverse
63
64
reverse:
65
lw $t7, ($t2)
lw $t9, $t8)
Sw $t7, ($t8)
sw $t9, ($t2)
#loading the array($t2 into $t7)
#loadibg the array($t8 into $t9)
#stores into array
#stores into array
66
67
69
70
add $t2, $t2, -4
add $t8, $t8, 4
bge $t8, $t2, print
#decrements the array, taking number from tail
#incremens the array, putting into the head
71
72
74
j reverse
75
76
77 print
883RRSRSRSE.
help_outline

Image Transcriptionclose

la $t8, array #loads array pointer 58 59 addi $t2, $t2, -4 add $t1, $t3, 0 60 #moves values from $t3 into $t1 61 62 j reverse 63 64 reverse: 65 lw $t7, ($t2) lw $t9, $t8) Sw $t7, ($t8) sw $t9, ($t2) #loading the array($t2 into $t7) #loadibg the array($t8 into $t9) #stores into array #stores into array 66 67 69 70 add $t2, $t2, -4 add $t8, $t8, 4 bge $t8, $t2, print #decrements the array, taking number from tail #incremens the array, putting into the head 71 72 74 j reverse 75 76 77 print 883RRSRSRSE.

fullscreen
check_circle

Expert Answer

star
star
star
star
star
1 Rating
Step 1

Note:

For the given code and attached image, the following explanation is briefly described about the reversing the array.

 

Step1:

Initially it reads ...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Science

Computer Architecture

Related Computer Science Q&A

Find answers to questions asked by student like you

Show more Q&A add
question_answer

Q: Draw a decision tree and find the number of key comparisons in the worst and average cases for the t...

A: Decision tree (enhanced bubble sort):

question_answer

Q: Imagine that you and your team have been hired to develop an improved process for evaluating which s...

A: Student's class 12th as well as his/her Entrance Exam will be checked.The information will be checke...

question_answer

Q: In python  Write a for loop (using the range() function) that will print the integers 10,15,20,25,30...

A: Program Instruction:Use range() function to start with 10 and end with 51 as range() function loops ...

question_answer

Q: I'm not sure how to make the clock show just seconds of the day and the remaining time with this pro...

A: Click to see the answer

question_answer

Q: Write a statement that outputs variable numObjects. End with a newline. Program will be tested with ...

A: As you have not specified the programming language, we are solving this question using Java programm...

question_answer

Q: What are whole disk encryption (WDE) solutions and under what circumstances are they required?

A: DefinitionWhole Disk Encryption (WDE) solutions, basically plays the foremost role in the field of c...

question_answer

Q: In protocol 6, the code for frame arrival has a section used for NAKs. This section is invoked if th...

A: NAK is an acronym for Negative Acknowledgment.ACK is an acronym for Acknowledgment.

question_answer

Q: Suppose that you want to solve a maximum flow problem containing parallel arcs, but the maximum flow...

A: Maximum Flow ProblemMaximum flow problem is a problem that invloves finding a feasible flow through ...

question_answer

Q: Describe the GRANT statement and explain how it relates to security. What types of privileges may be...

A: The syntax for GRANT statement is GRANT parameter(1) ON parameter(2) TO parameter(3) [WITH GRANT OPT...