Hello how are you all?
Ok as title suggests that i need bit of help in assembly language (MIPS)
1: I need to write a program that finds the biggest/smallest value in the array.
I have managed to find the biggest value but cant figure out the smallest.
2: I thought to sort out the array by using Bubble Sort and than print out the first and the last value to solve problem (1). But i couldn't implement Bubble sort in mips so i dropped that idea. Let me know if any one can help either sorting the array in ascending order or finding the smallest value.
My Code For Finding Biggest Value(Its Working Fine)
Ok as title suggests that i need bit of help in assembly language (MIPS)
1: I need to write a program that finds the biggest/smallest value in the array.
I have managed to find the biggest value but cant figure out the smallest.
2: I thought to sort out the array by using Bubble Sort and than print out the first and the last value to solve problem (1). But i couldn't implement Bubble sort in mips so i dropped that idea. Let me know if any one can help either sorting the array in ascending order or finding the smallest value.
My Code For Finding Biggest Value(Its Working Fine)
Code:
.data
array: .word 3, 9, 2, 1, 8, 2, 4, 6, 3, 8
arraylength: .word 10
max: .word 0
.text
.globl main
main:
la $s0, array # loading array
li $t1, 0 # index
add $t1, $t1, $zero # max
lw $t5, arraylength # number of elements
add $t2, $t2, $s0 # offset plus base
Loop:
beq $t0, $t5, Exit # Loop control ($t0==$t5)
lw $t3, 0($t2) # Getting First element of Array
add $t0, $t0, 1 # i++
add $t2, $t2, 4 # # update array address
slt $t4, $t1, $t3 # $t4 = 1 if $t1 is less than $t3, otherwise $t4 = 0
beq $t4, $zero, Loop # branch to loop if value in $t4 is equal to value in $zero
add $t1, $t3, $zero #
j Loop
Exit:
sw $t1, 0($t2) # Storing Highest Number
move $a0, $t1
li $v0, 1
syscall
li $v0, 10 # syscall to terminate
syscall