Question: .data getrange: .asciiz Enter range (in yards): tflight: .asciiz Time of flight: hmax: .asciiz Maximum height: theta: .asciiz Angle trajectory: newline:

.data

getrange: .asciiz "Enter range (in yards): "

tflight: .asciiz "Time of flight: "

hmax: .asciiz "Maximum height: "

theta: .asciiz "Angle trajectory: "

newline: .asciiz " "

space: .asciiz " "

pi: .float 3.14

g: .float 32.174

deg: .float 180.0

ftconv: .float 3.0

sec: .float 3600.0

temp: .float 1.0

error: .asciiz "Error! Enter the range in yards no more than 42240"

.text

main:

# print prompt and get user input for range

li $v0, 4 # print string syscall

la $a0, getrange

syscall

li $v0, 6 # read float syscall

syscall

move $t0, $v0

# validate input

li $t1, 42240 # 24 miles = 42240 yards

ble $t0, $t1, input_valid

li $v0, 4 # print string syscall

la $a0, error

syscall

j main

input_valid:

# convert yards to feet

li $t1, 3 # 3 feet per yard

mul $t0, $t0, $t1 # range in feet

# calculate time-of-flight

li $t1, 2500

lwc1 $f1, g # gravity

mul.s $f2, $f1, $f1 # g^2

mul.s $f3, $f2, $f2 # g^4

lwc1 $f4, temp # numerator

mul.s $f5, $f4, $f2 # numerator * g^2

li $t2, 2 # denominator

li $t6, 2 # initialize power of 2 to 2

li $t3, 3 # exponent

lwc1 $f6, temp # term

li $t4, 0 # sign

lwc1 $f7, temp # power of 2

lwc1 $f8, temp # factorial

lwc1 $f9, temp # angle in radians

li $t5, 1 # counter

lwc1 $f10, deg # conversion factor

lwc1 $f11, ftconv # feet in a yard

lwc1 $f12, sec # seconds in an hour

li $t5, 0 #initialize the counter to 0

#taylor series for sin to find tof

TaylorLoop:

# calculate term

div.s $f6, $f5, $f8

# add/subtract term

add.s $f4, $f4, $f6

sub.s $f4, $f4, $f6

# increment counter

addi $t5, $t5, 1

# calculate power of 2

mul.s $f7, $f7, $f2

move $t7, $t6 # move value of $t6 to $t7

li $t2, 0 # clear $t2

addi $t2, $t7, 0 # copy value of $t7 to $t2

addi $t6, $t6, 2 # update power of 2

# calculate factorial

mul.s $f8, $f8, $f9

add.s $f9, $f9, $f9

add.s $f9, $f9, $f9

# calculate numerator

mul.s $f4, $f4, $f3 #result of tof stored in $f4

# check for end of loop

bne $t5, 20, TaylorLoop

# calculate angle trajectory

li $t5, 2

lwc1 $f23, pi

mul.s $f9, $f4, $f1 #f4(results stored fot tof) * g($f1)

div.s $f10, $f9, $f12

mul.s $f11, $f10, $f11

mtc1 $t2, $f24 #convert the input value $t2 to float

cvt.s.w $f24, $f24

div.s $f12, $f11, $f24

div.s $f13, $f12, $f23

mul.s $f14, $f13, $f10

#calculate time of flight

div.s $f16, $f11, $f14

sqrt.s $f17, $f14

div.s $f18, $f16, $f17

mtc1 $t0, $f25 #convert the input value $t0 to float

cvt.s.w $f25, $f25

mul.s $f19, $f18, $f25

# print time of flight

li $v0, 4 # print string syscall

la $a0, tflight

syscall

li $v0, 2 # print float syscall

mov.s $f12, $f19

syscall

# print newline

li $v0, 4 # print string syscall

la $a0, newline

syscall

# calculate maximum height

mul.s $f20, $f16, $f17

div.s $f21, $f20, $f1

div.s $f22, $f21, $f24

# print maximum height

li $v0, 4 # print string syscall

la $a0, hmax

syscall

li $v0, 2 # print float syscall

mov.s $f12, $f22

syscall

# print newline

li $v0, 4 # print string syscall

la $a0, newline

syscall

# print angle trajectory

li $v0, 4 # print string syscall

la $a0, theta

syscall

li $v0, 2 # print float syscall

mov.s $f12, $f14

syscall

# print newline

li $v0, 4 # print string syscall

la $a0, newline

syscall

# exit program

li $v0, 10 # exit syscall

syscall

The MIPS code for the time of flight in seconds, maximum height in feet and angle trajectory in degrees does not work and give correct answers in MARS simulation. The output is given as NAN for all three things. Moreover, the range input check is not working as well when more than 42240 yards are being input, the error message does displays on the output. Please explain the purpose of each line and modify the code so that correct numbers for the time of flight, maximum height, and angle trajectory is calculated and displayed on the output. Make sure to use correct equations to calculate the time of flight, maximum height, and angle trajectory using Taylor series for trigonometric functions. I do not confirm that the above following code is correct or not correct. Thank you so much.

The following equations should be used:

.data getrange: .asciiz "Enter range (in yards): " tflight: .asciiz "Time of

Neglect the effects of air-resistance and curvature of the earth. tflight=g2v0sinhMAX=2gv02sin2R=gv02sin2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!