Advertisement
ChrisH41

Untitled

Mar 10th, 2023
1,049
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .data
  2. pi: .float 3.1415926
  3. input: .asciiz "Enter a number in yards: "
  4. bounds: .asciiz "Stay within 42240 yards! \n: "
  5. angleTraj: .asciiz "Angle Trajectory: "
  6. newLine: .ascii "\n"
  7. # All units below are in feet
  8. gravity: .float 32.1522
  9. velocity: .word 2500
  10.  
  11. .text
  12.  
  13. voidMain:
  14.    
  15.     # This will get the input in yards.
  16.     la $a0 , input
  17.     li $v0 , 4
  18.     syscall
  19.  
  20.     li $v0, 5 # wait for input
  21.     syscall
  22.  
  23.     move $a0, $v0  # a1 is a global varibale for other functions!
  24.     mul $a0, $a0, 3 # 1 yard = 3 feet
  25.     #Ensure that input >= 24 Miles / 42240 yard
  26.     li $t1, 42240
  27.     slt $t2, $t1, $a0   # if s0<t1, t2=1
  28.     beq $t2, 1, outOfBounds
  29.    
  30.     jal angle   # Jump to function angle
  31.     jal tFlight
  32.    
  33.    
  34.    
  35.     j voidMain
  36.    
  37.    
  38. outOfBounds:
  39.     #bnez $t2, voidMain # if t2 != 0, goto main
  40.    
  41.     # This will get the input in yards.
  42.     la $a0 , bounds
  43.     li $v0 , 4
  44.     syscall
  45.  
  46.     j voidMain
  47.    
  48. angle:
  49.  
  50.     # Load constants into variables.
  51.     lwc1 $f0, gravity
  52.     lwc1 $f1, pi
  53.     lw $t0, velocity
  54.    
  55.      #convert the input value to float
  56.     mtc1 $a0, $f2
  57.     cvt.s.w $f2, $f2
  58.  
  59.     mul.s $f2, $f0, $f2 # range * gravity
  60.     mul $t0, $t0, $t0 # Velocity * Velocity
  61.    
  62.     #convert the velcocity value to float
  63.     mtc1 $t0, $f3
  64.     cvt.s.w $f3, $f3
  65.    
  66.     # (range * gravity) / V^2
  67.     div.s $f2, $f2,$f3
  68.     #mtc1 $f2,$f2
  69.     mfc1 $a0, $f2    # allows us to pass float to arcSin func.
  70.    
  71.     # This stores the address of main so we can jump back to it
  72.     move $s3, $ra
  73.     jal arcSin
  74.     jr $s3
  75.    
  76.     li $v0, 10
  77.     syscall
  78.  
  79. arcSin:
  80.    
  81.     # **We will expand a power series to n = 10 given X** #
  82.    
  83.     # Initialize vars.
  84.    
  85.     # x =  range * gravity / v^2
  86.    
  87.     la $t0, ($a0) # Sum = X
  88.     mtc1 $t0, $f0 # Actual SUm
  89.     mtc1 $t0, $f1 # Temp sum
  90.     mtc1 $t0, $f11 # constant X
  91.    
  92.     li $t1, 3 # power
  93.     li $t2, 1 # counter
  94.     li $t3, 6
  95.     mtc1 $t3, $f2 # divisor
  96.     cvt.s.w $f2, $f2 # NEEDED to divide correctly
  97.    
  98.     loop: beq $t1, $t2, p3
  99.         addi $t2, $t2, 1 # Increment counter
  100.         mul.s $f1, $f1, $f11 # sux * x
  101.         j loop
  102.        
  103.     loop2: beq $t1, $t2, endLoops
  104.         addi $t2, $t2, 1 # Increment counter
  105.         mul.s $f1, $f1, $f11 # sux * x
  106.         j loop2
  107.    
  108.     p3:
  109.         div.s $f1, $f1, $f2 # tempSum / 6
  110.         add.s $f0, $f0, $f1 # sum += tempSum
  111.         mov.s $f1, $f11 # reset tempSu
  112.         li $t1, 5 # change the power to 5
  113.         li $t2, 1 # resset counter
  114.         j loop2
  115.     endLoops:
  116.         li $t3, 40
  117.         mtc1 $t3, $f2 # divisor
  118.         cvt.s.w $f2, $f2 # NEEDED to divide correctly
  119.         div.s $f1, $f1, $f2 # tempSum / 4
  120.         add.s $f0, $f0, $f1 # sum += tempSum
  121.         mfc1 $a0, $f0 # radian version --> Use for later for flightTime,
  122.         lwc1 $f1, pi
  123.         li $t3, 180   # 180 degrees
  124.         mtc1 $t3, $f2
  125.         cvt.s.w $f2, $f2
  126.         mul.s $f0, $f0, $f2
  127.         div.s $f0, $f0, $f1
  128.        
  129.    
  130.    
  131.    
  132.    
  133.     la $a0 , angleTraj
  134.     li $v0 , 4
  135.     syscall
  136.    
  137.     mov.s $f12, $f0 # return summation 
  138.    
  139.     li $v0, 2
  140.     syscall
  141.    
  142.     mfc1 $s1, $f12
  143.    
  144.     la $a0 , newLine
  145.     li $v0 , 4
  146.     syscall
  147.    
  148.     jr $ra
  149.    
  150. tFlight:
  151.     lwc1 $f0, gravity
  152.     lw $t0, velocity
  153.    
  154.     mul $t0, $t0, 2 #v *2
  155.     jal arcSin
  156.     mtc1 $a0, $f0
  157.     mov.s $f12, $f0 # return summation 
  158.    
  159.     li $v0, 2
  160.     syscall
  161.        
  162.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement