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.
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.
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
100%
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
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education