Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .data
- msg1: .asciiz "Please enter the degree of Polynomial:"
- msg2: .asciiz "Please enter left bound."
- msg3: .asciiz "Please enter right bound."
- msg4: .asciiz " Please enter coefficient until N-1 is complete."
- offset: .float .0001 #where the bounds are going to be stored
- .text
- Main:
- li $v0,4
- la $a0, msg1
- syscall
- li $v0, 5
- syscall
- move $a0,$v0
- li $v0,1
- syscall #checks print degree
- move $s1,$a0 #-------------------------------$s1 holds degree for entire project
- li $v0,4
- la $a0, msg2
- syscall
- li $v0, 5
- syscall
- move $a0,$v0
- li $v0,1
- syscall #checks print left bound
- move $s0,$a0 #--------------------------------$s0 holds left bound
- li $v0,4
- la $a0, msg3
- syscall
- li $v0, 5
- syscall
- move $a0,$v0
- li $v0,1
- syscall #checks print right bound
- move $s2,$a0 #---------------------------------$s2 holds right bound
- #Allocate memory in the stack
- li $s3, 4 #size of integer 4 bytes
- mul $s3, $s3, $s1 #compute the size of the array of coefficients
- addi $s3, $s3, 12 #create 2 more additional places in memory
- sub $sp, $sp, $s3 #make room on stack for coefficients
- sw $ra, 0($sp)
- sw $s4, 4($sp)
- j Fillcoef
- Fillcoef:
- # This for loop will be called from main and fill and array of coefficients
- slt $t2,$t0,$s1
- beq $t2,$zero,start
- li $v0,4
- la $a0, msg4
- syscall
- li $f0,6
- syscall
- s.s $f0, 4($sp)
- move $t2,$f0 #move user input into temp register
- sw $t2,8($sp) #store the coefficient
- addi $sp, $sp, 4 #increment stack pointer
- addi $t0,$t0,1 #increment counter
- b Fillcoef
- start:
- # This will compute the slope and out the coordinates of the minimum
- addi $t0, $zero, -1
- sw $t0, 4($sp)
- lwc1 $f0, 4($sp) # This is dydx or derivative
- cvt.s.w $f0, $f0 # convert from float precision
- add $t0, $zero, $s0 #add left bound limit to stack
- sw $t0, 4($sp)
- lwc1 $f1, 4($sp)
- cvt.s.w $f1,$f1 # x0 will start at the left bound limit
- computeSlope:
- add $t0,$zero,$zero
- sw $t0, 4($sp)
- lwc1 $f31,4($sp)
- cvt.s.w $f31,$f31 # set $f31 to zero
- c.lt.s $f0, $f31 # Check to see if slope is negative
- bc1f end # continue loop if slope is negative
- jal doEquation # find y value
- add $t0, $zero, $v0
- sw $t0, 4($sp)
- lwc1 $f3, 4($sp)
- cvt.s.w $f3,$f3
- l.s $f30,offset
- sub.s $f4, $f1,$f30 # xOne X0 - .0001
- add.s $f5, $f1, $f30 # xTwo x0 + .0001
- jal doEquation # find yOne using xOne as x0
- add $t0, $zero, $v0
- sw $t0, 4($sp)
- lwc1 $f6, 4($sp)
- cvt.s.w $f6,$f6
- jal doEquation # find yTwo using xTwo as x0
- add $t0, $zero, $v0
- sw $t0, 4($sp)
- lwc1 $f7, 4($sp)
- cvt.s.w $f7,$f7
- # calculate derivative yTwo-Yone/x2-x1
- sub.d $f6, $f7, $f6
- sub.d $f4, $f5, $f4
- div.d $f0, $f6, $f4 #derivative has changed
- # solve for x where x = x0 - y value/dydx
- div.d $f4, $f3, $f0
- # make x0 = x
- mov.s $f1, $f4
- b computeSlope
- doEquation:
- xor $v0, $v0, $v0 # set $vo to zero
- resetSP:
- #sub &sp, &sp, $s1 #move the stack pointer to the beginging of the array
- end:
- #print out the coordinates
- jal doEquation #find last y-coordinate
- add $t0, $zero, $v0
- sw $t0, 4($sp)
- lwc1 $f4, 4($sp)
- cvt.s.w $f4,$f4
- #Print out "the coordinates are ($f1, $f4)"
- lw $ra, 0($sp) #restore $ra
- lw $s4, 4($sp)
- addi $sp, $sp, 4 #shrink stack
- jr $ra
Add Comment
Please, Sign In to add comment