Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.5 kB
3
Indexable
Never
# a = t1
# b = t2
# c = t3
# d = t4
main:
la $a0,label_insert_a  #set A parameter
jal print
li $v0,5
syscall
move $t1,$v0
beqz $t1,invalid_param

la $a0,label_insert_b #set B parameter
jal print
li $v0,5
syscall
move $t2,$v0 

la $a0,label_insert_c #set C parameter
jal print
li $v0,5
syscall
move $t3,$v0 

#calc d parameter
mul $t6,$t1,0x4 #calc 4*a = t3
mult $t2,$t2  #calc b*b = LO
msub $t6,$t3 # lo - 4*a*c
la $a0,label_eq_d #print d
jal print
li $v0,1
mflo  $t4
move $a0,$t4
syscall
la $a0,new_line 
jal print

beqz $t4,delta_eq_zero
bgtz   $t4,delta_bigger_than_zero


invalid_param:
la $a0,invalid_a
jal print
j finish

delta_eq_zero:
mul $t3,$t1,0x2
mul $t2,$t2,-1
div $t2,$t3
mflo $a0
jal print
j finish

delta_bigger_than_zero:
mtc1 $t4,$f4
cvt.s.w $f4,$f4 # D
mtc1 $t1,$f1
cvt.s.w $f1,$f1 # A
mtc1 $t2,$f2
cvt.s.w $f2,$f2 # B
mtc1 $t3,$f3
cvt.s.w $f3,$f3 # C

#(-b) = f2
sub.s $f10,$f10,$f2
mov.s $f2,$f10

#sqrt(d) = f4
sqrt.s $f4,$f4

#2*a = f1
add.s $f1,$f1,$f1


#f2-f4 / f1
sub.s $f7,$f2,$f4
div.s $f7,$f7,$f1

add.s $f8,$f2,$f4
div.s $f8,$f8,$f1

li $v0,2
mov.s $f12,$f6
syscall

li $v0,2
mov.s $f12,$f7
syscall

j finish

delta_bigger_less_zero:
j finish

print:
li $v0,4
syscall
jr $ra

finish:

.data
	label_insert_a: .asciiz "Insert a:\n"
	invalid_a: .asciiz "a=0 its linear equalization\n"
 	label_insert_b: .asciiz "Insert b:\n"
	label_insert_c: .asciiz "Insert c:\n"
	new_line: .asciiz "\n"
	label_eq_d: .asciiz "d="
	no_solutions: .asciiz "there is no solutions"