Java
Java
Java
data
filas: .byte 3
columnas: .byte 5
matriz: .half 3, 1, 5, -2, 8, 4 -7, 12, 10, 9, 1, 24, -1, 60, 10
.align 1
max: .space 2
lf: .asciiz "\n"
space: .asciiz " "
.text
printm:
# inputs:
# $a0: matrix address (half)
# $a1: n-rows
# $a2: n-columns
# outputs:
# None
move $t8, $a0
li $t0, 0
printmfor:
bge $t0, $a1, printmendfor
li $t1, 0
printmfor2:
beq $t1, $a2, printmendfor2
mul $t2, $t0, $a2 #i*N
add $t3, $t2, $t1 #i*N+j
sll $t4, $t3, 1
add $t5, $t8, $t4
lh $a0, 0($t5)
li $v0, 1
syscall
la $a0, space
li $v0, 4
syscall
addi $t1, $t1, 1
j printmfor2
printmendfor2:
la $a0, lf
li $v0, 4
syscall
add $t0, $t0, 1
j printmfor
printmendfor:
jr $ra
.globl main
main:
addi $sp, $sp, -8 # subroutine foreword
sw $fp, 0($sp)
endfor:
lw $ra, 4($fp) # subroutine epilogue
lw $fp, 0($fp)
addi $sp, $sp, 8
#-----------------------------------------------------
la $a0, matriz
lb $a1, filas
lb $a2, columnas
jal printm
#-----------------------------------------------------
li $v0, 10 # system call for exit
syscall # we are out of here.
# inputs:
# $a0: matrix address (half)
# $a1: n-columns
# $a2: i
#k=a3+1
# AA=A[i,k]
#principiopara
# beq k, a1 finpara
# a=max
# b=AA
# bge a,b, finsi
# temp = *max;
# *max = A[i,k];
# A[i,k] = temp;
#finsi:
# k=k+1
# saltar a principiopara
#finpara:
# guardar registros
addi $sp, $sp, -28
sw $ra, 24($sp)
sw $s0, 20($sp)
sw $s1, 16($sp)
sw $s2, 12($sp)
sw $s3, 8($sp)
sw $s4, 4($sp)
sw $s5, 0($sp)
bucle3for:
bge $s4, $a1,fin_bucle3
addi $t2, $s5, 0 # a = max
addi $t3, $s0, 0 # b = A[i,k]
finsi:
addi $s4, $s4, 1 # K =K+1
j bucle3for
fin_bucle3:
lw $s5, 24($sp)
lw $s4, 20($sp)
lw $ra, 16($sp)
lw $a0, 12($sp)
lw $a1, 8($sp)
lw $a2, 4($sp)
lw $a3, 0($sp)
addi $sp, $sp, 28
lw $fp, 0($sp)
addi $sp, $sp, 4
jr $ra