Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
1.4 kB
1
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 $t3,$t1,0x4 #calc 4*a = t3
mult $t2,$t2  #calc b*b = LO
msub $t3,$t2 # 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 $t7,delta_bigger_eq_zero
bltz $t7,delta_bigger_less_zero


invalid_param:
la $a0,invalid_a
jal print
j finish

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

delta_bigger_eq_zero:
mtc1 $t4,$f0
mtc1 $t1,$f1
mtc1 $t2,$f2
mtc1 $t3,$f3

sqrt.s $f0,$f0 # sqrt(d)
l.s $f10,-1
mul.s $f2,$f2,$f10
add.s  $f5,$f2,$f0 # f5 = (-b+sqrt(d))
sub.s  $f6,$f2,$f0 # f6 = (-b-sqrt(d))
l.s $f10,2
mul.s $f11,$f11,$f10
div.s $f5,$f5,$f11
div.s $f6,$f6,$f11
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"