Welcome to the Final Exam!
You have been hired as a Contractor by Stark Industries to help with the development of the Jarvis-2022 Bomb Sight.
Your job will be be write the most critical elements of the Bomb Sight Code.
These include the elements that will retrieve the target data, calculate the drop solution and finally pass the data on for use by other systems.
Good Luck Tony Stark is watching!
The angle of the Target from the Aircraft is A1 and the angle of the Aircraft relative to the vertical y is 90-A1.
The direct distance of the Aircraft to the Target or Range is d.
The Aircraft drops the ordnance, allowing it to free fall to the target.
The Aircraft is traveling a a speed of Vx m/s.
The important equations are;
- y=d*cos(90-A1), where A1 is in degrees
- x=d*sin(90-A1), where A1 is in degrees
- y=0.5*a*t^2, where a=9.8 m/s^2
- x’=Vx*t
The vertical distance above ground is measured by a radar altimeter and provided in meters.
Given the knowns above x’, t and d can be solved for.
Note x’ does not equal x.
x’ is the distance the ordinance will travel in time t (the time the ordinance is in free fall).
x is the current x distance to the target.
1a. d=y/cos(90-A1)
2a. From 1a and 1 above solve for x
3a. y is given solve for t or t=sqrt(2y/a)
The cos(x) and sin(x) can be solved for from a Taylor Series Expansion.
sin(x)=(-1^n/(2*n+1)!)*x^(2*n+1) for n=0…
cos(x)=(-1^n/(2*n)!)*x^(2*n) for n=0…
Note x above is in radians where 2*PI radians = 360 degrees…all angles need to be converted to radians from degrees and back!
To restate the following data is provided to the Jarvis-2022.
- Vx i m/s
- y in m
- A1 in degrees
Data will be received as ASC encoded characters in a buffer in the following format;
“UPDATE A1:XXX DEGREES, Y XXX METERS, VX XXX M/S”
Where the X’s indicate ASC digits for the A1, Y and VX values.
The input string must be decoded to extract the required data for calculations.
For the exam simply create test buffers for use in testing your application.
The output of the Jarvis-2022 must be another ASC buffer in the following format;
“SOLUTION DROP IN XXX SECS”
Where XXX represents the drop time in seconds.
The drop time is the time given by (x-x’)/Vx and represents the time delay required to ensure when the ordinance is dropped that it will free fall on to the target.
Note if the drop time is negative this represents the case where the Aircraft is too close for a free fall drop.
The output should be “SOLUTION ABORT!” in this case.
Your application should support a test mode to allow the input of the target data from STDIN (keyboard) and display the results to STDOUT (monitor).
Test mode should be entered by the user inputting ‘TEST’ from STDIN (keyboard).
Test mode should be exited by the user inputting ‘NORMAL’ from STDIN (keyboard).
Please submit your s files, demo snips of your application in operation using the test mode and normal mode along with a word document detailing your design.
Submit all of your results in a single zip file.
Good Luck & have a nice summer break!
- The maximum amount of leading 0s before a number is 12
- The input into normal mode is assumed to be valid
- stdout is used as the buffer for normal mode due to time constraints
- had I been able to use the clib, I would have used sprintf and been done :(
- it is also possible to read from stdout, so I am assuming that is possible that the other systems could listen to it
exit.s exits the program. It has multiple different versions of the function. All use raw service calls to exit.
exit is the most simple way of exiting, and exits with an exit code of 0
Exit syscall but with an exit code of 1
exit syscall, but the exit code is expected in r0
- r0 <– exit code
exit syscall, however we will write a message to stdout in the process.
Stack:
- length of error message (pop 1)
- address of error message (pop 2)
r0 <– Exit code
ascii to int takes in an addr of a string of an integer, and returns the integer contained in the string as an integer
- r0 <– addr of str
- r1 <– len of str
- r0 <– integer
cos is a wrapper for sin. It uses trig identities to map all inputs of cos to sin, so I don’t need to implement cosine :)
- r0 <– input
- r0 <– result
sin uses the taylor series to calculate the sin function. It runs for 35 iterations of it
- r0 <– input
- r0 <– result
converts degrees to radians, accepting either an int or a float as an arg
- r0 <– integer
- r0 <– result (float)
- r0 <– float
- r0 <– result (float)
runs the factorial operation on r0
- r0 <– float
- r0 <– result (float)
- r0 <– int
- r0 <– result (int)
- r0 <– int
- r0 <– result (float)
runs the calculations to determine when to drop the bomb. I do things very slightly differently than the question calls for, because I use trig identities. Further, I use a slightly different method of getting the final answer (I subtract time to target from drop time)
- r0 <– angle (degrees, float)
- r1 <– height (meters, float)
- r2 <– velocity (m/s, float)
- r0 <– result
gets the amount of leading 0s in the decimal part of a floating point number
- r0 <– address of float
- r0 <– result (int)
- r0 <– float
- r0 <– result (int)
Retrieves the decimal and integral parts of a float. The integral part is returned as an integer, and the decimal part is returned as a float
- r0 <– float
- r1 <– result (int)
- r0 <– float
- r1 <– result (float)
- r0 <– float
- r1 <– integral part
- r2 <– decimal part
The driver of the program. Reads input, checks modes. CONTAINS THE ENTRY POINT _start
parses the string passed in during normal mode operation
- r0 <– pointer to string
- r1 <– address of where to store A1
- r2 <– address of where to store Y
- r3 <– address of where to store vx
- This function does not return anything. Instead, it
- writes to the mem addresses specified in r1, r2, and r3
- modifies the string pointed to at r0, such that verifyInput.s can prepare the data for strToFloat.s
gets the power of a number
- r0 <– base (float)
- r1 <– eponent (int)
- r0 <– result
this is the very same printDecimal that I used for program 5. It prints a decimal to stdout
- r0 <– int (to print)
takes in a string and returns the float contained in the str
- r0 <– addr of integral part
- r1 <– len of integral part
- r2 <– addr of decimal part
- r3 <– len of decimal part
- r0 <– result (float)
takes in a string of either an int or a float and verifies that it is a valid number. MUST BE CALLED BEFORE strToFloat or asciiToInt
- r0 <– addr of string
- r1 <– len of int
- r0 <– addr of string
- r0 <– addr of integral part of float (unchanged)
- r1 <– len of integral part of float
- r2 <– addr of decimal part of float
- r3 <– len of decimal part of float
write-float.s prints a floating point number as decimal to stdount.
- r0 <– address of float
- when prompted type NORM
- when prmpted type TEST
- when inputting the number, type in a floating point number WITH THE DECIMAL, it is expected.