Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .data
- prompt1: .asciiz "Enter your p\n"
- prompt2: .asciiz "Enter your q\n"
- onesolution: .asciiz "There is the following solution: "
- nosolution: .asciiz "There is no solution\n"
- twosolutions: .asciiz "The first solution: "
- twosolutionstwo: .asciiz "The second solution: "
- again: .asciiz "\nType 0 to stop running. Enter any other integer to continue"
- leer: .asciiz "\n"
- divideby4: .double 4
- storezero: .double 0
- divideby2: .double 2
- storeminus1: .double -1
- .text
- main:
- loop:
- l.d $f18,storeminus1 #18 enthält -1
- l.d $f10,divideby4 #f10 enthält 4
- l.d $f8,storezero #f8 enthält 0
- l.d $f6,divideby2 #f6 enthält 2
- la $a0,prompt1 #Asks for P
- li $v0,4
- syscall
- li $v0,7
- syscall
- mov.d $f12,$f0 #f12 stores the P
- la $a0,prompt2 #Asks for Q
- li $v0,4
- syscall
- li $v0,7
- syscall
- mov.d $f14,$f0 #f14 stores the Q
- jal diskriminante
- jal equaltozero
- jal smallerthanzero
- j loop
- ##############################################################################
- diskriminante:
- mul.d $f2,$f12,$f12 #$f2 enthält jetzt unser D
- div.d $f2,$f2,$f10
- sub.d $f2,$f2,$f14
- jr $ra
- equaltozero: #checks if the number is 0
- c.eq.d $f2,$f8 #this function checks whether its equal as double precision and then puts a flag
- bc1t resultzero #checks the prev. set flag
- jr $ra
- smallerthanzero:#checks for whether it needs to jump in the bigger or smaller than 0 part
- c.lt.d $f2,$f8
- bc1t minusnumber
- bc1f plusnumber
- ############################################################################
- minusnumber: #when the number is <0
- la $a0,nosolution
- li $v0,4
- syscall
- j continue
- ###########################################################################
- plusnumber: #when the number is >0
- div.d $f12,$f12,$f6 #calculates -p/2 and the root of D
- mul.d $f12,$f12,$f18
- sqrt.d $f2,$f2
- sub.d $f20,$f12,$f2 #saves the result of the subtraction in f20
- add.d $f12,$f12,$f2 #saves the result of the addition in f12
- la $a0,twosolutions #just the syscalls for printing the msg and the double number
- li $v0,4
- syscall
- li $v0, 3
- syscall
- la $a0,leer
- li $v0,4
- syscall
- la $a0,twosolutionstwo
- li $v0,4
- syscall
- mov.d $f12,$f20 #Need to move the 2nd solution to f12 to get it outputable
- li $v0,3
- syscall
- j continue
- ############################################################
- resultzero: #When the result of the equotion is 0
- la $a0,onesolution
- li $v0,4
- syscall
- div.d $f12,$f12,$f6 #divides the P with 2
- mul.d $f12,$f12,$f18 #Multiplies it with -1 to get the -
- li $v0,3
- syscall
- j continue
- ##########################################Just for looping the previous
- continue:
- la $a0,again
- li $v0,4
- syscall
- li $v0,5
- syscall
- beqz $v0,end
- j loop
- end:
- li $v0,10
- syscall
- #########################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement