I need help on this MIPS Code: #Write MIPS that searches array of words for the
ID: 3791866 • Letter: I
Question
I need help on this MIPS Code:
#Write MIPS that searches array of words for the biggest and smallest element
#the directive .word is used to set up an array of 20 4-byte words
#in the data section
#t1-- contains count of elements
#t2-- contains min value
#t3-- contains max value
#t4-- each word from array in turn
.data
anArray: .word 3,4,2,6,223,345,121,92,99,14,7,76,67,49,56,43,7,81,21,31
count: .word 20
Thursday: .asciiz "TODAY IS THURSDAY FEB 09, 2017"
result1: .asciiz " The minimum value is ="
result2: .asciiz " The maximum value is ="
bye: .asciiz " You have anice weekend and I will see you on Tuesday Feb 14 "
.text
.globl main
main:
la $s0, anArray
li $v0,4
syscall
la $s1, count
li $v0,4
syscall
la $a0, Thursday
li $v0,4
syscall
la $a0, result1
li $v0,4
syscall
la $a0, result2
li $v0,4
syscall
la $a0, bye
li $v0,4
syscall
search:
lw $s1, 4($s2) # get &anArray
lb $s2, 4($s2) # get count
move $s3, $s4
addi $s4, $s4, 20 # $s4 = count + 20
Loop:
la $t0, 4
beqz anArray ($t4), $s0, result2
blt anArray ($t1), $s1, result1
addi $t1, $t1,1 # increment
addi $t3, $t3, +4 # decrement loop counter
li $t4, +4
j Loop
result1:
move $v0, anArray($t1)
syscall
result2:
move $v0, anArray($t2)
syscall
la $a0, bye
li $v0,4
syscall
li $v0, 10
syscall
I don't know if I'm on the right way.
Explanation / Answer
The way you are going is right. No problem with that. But, you are going in a very complicated way.May be you are thinking in very different way.So,I don't want to distract that. If you want then just go through the things following it might help you :-
If you want me to simplify my statements then please let me know. But, what you are doing is right too
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.