Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #dev note compute time is more valuable than computer hardware
- .data
- #useful nmumbers
- four: .double 4.0
- two: .double 2.0
- zero: .double 0.0
- #user questions
- pq: .asciiz "q > "
- qq: .asciiz "p > "
- slcnt: .asciiz " solution(s)\n"
- solone: .asciiz "\n solution 1: "
- soltwo: .asciiz "\n solution 2: "
- .text
- #pq dialog
- la $a0, pq
- li $v0, 4
- syscall
- #pa dialog
- li $v0, 7
- syscall
- mov.d $f14, $f0 #move p to reg f14
- #qq dialog
- la $a0, qq
- li $v0, 4
- syscall
- #qa dialog
- li $v0, 7
- syscall
- mov.d $f12, $f0 #move p to reg f14
- jal quadsolve
- ##### output ####
- add $a0, $zero, $t0 #print solution count
- li $v0, 1
- syscall
- li $v0, 4
- la $a0, slcnt #print solution count text
- syscall
- beqz $t0, end #when no solution over here
- #### min 1 solution ####
- li $v0, 4
- la $a0, solone #print solution one text
- syscall
- mov.d $f12, $f0 #load solution one in output register
- li $v0, 3
- syscall
- subiu $t0, $t0, 1
- beqz $t0, end
- #### full 2 solutions ####
- li $v0, 4
- la $a0, soltwo #print solution two text
- syscall
- mov.d $f12, $f2
- li $v0, 3
- syscall
- j end # ends programm
- #q is $f12 - $f13
- #p is $f14 - $f15
- #D is $f16 - $f17
- #-p/2 is $f8-$f9
- quadsolve:
- #set some helpful values
- l.d $f10, zero
- l.d $f18, four
- #calc d
- mul.d $f16, $f14, $f14
- div.d $f16, $f16, $f18
- sub.d $f16, $f16, $f12
- # -p/2 errechenen
- l.d $f18, two #f18 is now 2
- sub.d $f8, $f10, $f14
- div.d $f8, $f8, $f18
- #check if d is 0 or smaller
- c.lt.d $f16, $f10
- bc1t no
- c.eq.d $f16, $f10
- bc1t single
- j double
- double:
- l.d $f18, two #f18 is now 2
- sqrt.d $f16, $f18
- sub.d $f0, $f8, $f16 #return -p/2 - d in $f0
- add.d $f2, $f8, $f16 #return -p/s + d in $f2
- li $t0, 2
- jr $ra
- single:
- mov.d $f8, $f0 #return -p/2 in $f0
- li $t0, 1
- jr $ra
- no:
- li $t0, 0 #return nothing in $f0 and $f2
- jr $ra
- end:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement