0% found this document useful (0 votes)
18 views3 pages

Java

Uploaded by

Acoran Gonzalez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views3 pages

Java

Uploaded by

Acoran Gonzalez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

.

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

# $a3: max addres (half)


# outputs:
# None
#
# Put your code here
#
# ...
# guardar $fp

#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:

addi $sp, $sp, -4


sw $fp, 0($sp)
add $fp, $sp, $0

# 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)

addi $s0, $a0, 0 #direccion de comienzo del vector


addi $s1, $a1, 0 # N
addi $s2, $a2, 0 # i
addi $s3, $a3, 0 # j
addi $s4, $s6, 1 # k = j+1
addi $s5, $sp, 0 # extraer max del registro usado en bucle2
# matriz = matriz + (i* columnas)*2 + j*2
mul $t0,$s2,$s1 # i * N
li $t1, 2 #cargar un 2
mul $t0, $t0, $t1 # 2*(i*N)
mul $t2, $s3, $t1 # j*2
add $t0, $t0, $t2 # (2*(i*N))+j*2
add $s0, $s0, $t0
addi $t0, $s0, 0

#crear A[i,k] -------^

bucle3for:
bge $s4, $a1,fin_bucle3
addi $t2, $s5, 0 # a = max
addi $t3, $s0, 0 # b = A[i,k]

bge $t2, $t3,finsi


addi $t4, $t2, 0 #temp = max
lh $t0, 0($s0) #*max = A[i,k]
sh $t0, 0($s5)
add $t0, $t0, $t4 #A[i,k] = temp

addi $s4, $s4, 1 # K = K+1


j bucle3for

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

You might also like