Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .data
- pi: .float 3.1415926
- input: .asciiz "Enter a number in yards: "
- bounds: .asciiz "Stay within 42240 yards! \n: "
- angleTraj: .asciiz "Angle Trajectory: "
- newLine: .ascii "\n"
- # All units below are in feet
- gravity: .float 32.1522
- velocity: .word 2500
- .text
- voidMain:
- # This will get the input in yards.
- la $a0 , input
- li $v0 , 4
- syscall
- li $v0, 5 # wait for input
- syscall
- move $a0, $v0 # a1 is a global varibale for other functions!
- mul $a0, $a0, 3 # 1 yard = 3 feet
- #Ensure that input >= 24 Miles / 42240 yard
- li $t1, 42240
- slt $t2, $t1, $a0 # if s0<t1, t2=1
- beq $t2, 1, outOfBounds
- jal angle # Jump to function angle
- jal tFlight
- j voidMain
- outOfBounds:
- #bnez $t2, voidMain # if t2 != 0, goto main
- # This will get the input in yards.
- la $a0 , bounds
- li $v0 , 4
- syscall
- j voidMain
- angle:
- # Load constants into variables.
- lwc1 $f0, gravity
- lwc1 $f1, pi
- lw $t0, velocity
- #convert the input value to float
- mtc1 $a0, $f2
- cvt.s.w $f2, $f2
- mul.s $f2, $f0, $f2 # range * gravity
- mul $t0, $t0, $t0 # Velocity * Velocity
- #convert the velcocity value to float
- mtc1 $t0, $f3
- cvt.s.w $f3, $f3
- # (range * gravity) / V^2
- div.s $f2, $f2,$f3
- #mtc1 $f2,$f2
- mfc1 $a0, $f2 # allows us to pass float to arcSin func.
- # This stores the address of main so we can jump back to it
- move $s3, $ra
- jal arcSin
- jr $s3
- li $v0, 10
- syscall
- arcSin:
- # **We will expand a power series to n = 10 given X** #
- # Initialize vars.
- # x = range * gravity / v^2
- la $t0, ($a0) # Sum = X
- mtc1 $t0, $f0 # Actual SUm
- mtc1 $t0, $f1 # Temp sum
- mtc1 $t0, $f11 # constant X
- li $t1, 3 # power
- li $t2, 1 # counter
- li $t3, 6
- mtc1 $t3, $f2 # divisor
- cvt.s.w $f2, $f2 # NEEDED to divide correctly
- loop: beq $t1, $t2, p3
- addi $t2, $t2, 1 # Increment counter
- mul.s $f1, $f1, $f11 # sux * x
- j loop
- loop2: beq $t1, $t2, endLoops
- addi $t2, $t2, 1 # Increment counter
- mul.s $f1, $f1, $f11 # sux * x
- j loop2
- p3:
- div.s $f1, $f1, $f2 # tempSum / 6
- add.s $f0, $f0, $f1 # sum += tempSum
- mov.s $f1, $f11 # reset tempSu
- li $t1, 5 # change the power to 5
- li $t2, 1 # resset counter
- j loop2
- endLoops:
- li $t3, 40
- mtc1 $t3, $f2 # divisor
- cvt.s.w $f2, $f2 # NEEDED to divide correctly
- div.s $f1, $f1, $f2 # tempSum / 4
- add.s $f0, $f0, $f1 # sum += tempSum
- mfc1 $a0, $f0 # radian version --> Use for later for flightTime,
- lwc1 $f1, pi
- li $t3, 180 # 180 degrees
- mtc1 $t3, $f2
- cvt.s.w $f2, $f2
- mul.s $f0, $f0, $f2
- div.s $f0, $f0, $f1
- la $a0 , angleTraj
- li $v0 , 4
- syscall
- mov.s $f12, $f0 # return summation
- li $v0, 2
- syscall
- mfc1 $s1, $f12
- la $a0 , newLine
- li $v0 , 4
- syscall
- jr $ra
- tFlight:
- lwc1 $f0, gravity
- lw $t0, velocity
- mul $t0, $t0, 2 #v *2
- jal arcSin
- mtc1 $a0, $f0
- mov.s $f12, $f0 # return summation
- li $v0, 2
- syscall
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement