Last active
September 2, 2015 10:44
-
-
Save aziflaj/ebe64a12eab84d0eba07 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.data | |
numarray: .word 2, 5, 48, 6, 9 | |
sizearray: .word 5 | |
maxtext: .asciiz "\nThe maximum of array: " | |
indextext: .asciiz "\nThe index (zero based) of maximum: " | |
.text | |
main: | |
la $a0, numarray # load the array of nubers | |
lw $a1, sizearray # load the size of array | |
jal max # call procedure max | |
move $s0, $v0 # store max value into $s0 | |
move $s1, $v1 # store max index into $s1 | |
# print the maximum | |
la $a0, maxtext | |
li $v0, 4 | |
syscall | |
move $a0, $s0 | |
li $v0, 1 | |
syscall | |
# print the index | |
la $a0, indextext | |
li $v0, 4 | |
syscall | |
move $a0, $s1 | |
li $v0, 1 | |
syscall | |
# end of program | |
li $v0, 10 | |
syscall | |
# # # # # # # # # # # # # # # | |
# # # procedure max definition # # # | |
max: | |
add $t0, $zero, $zero | |
add $v0, $zero, $zero | |
add $v1, $zero, $zero | |
cikel: | |
sltu $t2, $t0, $a1 | |
beq $t2, $zero, fund | |
lw $t1, 0($a0) | |
sltu $t2, $t1, $v0 | |
bne $t2, $zero, kalo | |
add $v0, $t1, $zero | |
add $v1, $t0, $zero | |
kalo: | |
addi $t0, $t0, 1 | |
addi $a0, $a0, 4 | |
j cikel | |
fund: | |
jr $ra |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment