COSC 2406 Lab 10 - Floating Point Programming
Coding: submit all asm files to the LMS.
The Area Calculator. Prompt for the side length of a square, the length and width of a rectangle,
and the radius of a circle. Use the floating-point unit to calculate the area of each. For
reference, the area formulas are noted below. The FPU stack must be empty after your program
is finished. Some hints are below. You must show the FPU stack at the end. -1 mark for a
non-empty FPU stack.
Formulas:
• Square: $A = s^2$
• Rectangle: $A = l \times w$
• Circle: $A = \pi r^2$
Hints:
• Remember to use the FINIT instruction before starting any FPU operations to clear the
exception status. You don't know if another program could have set some flags.
• Use the type Real4 for all floating-point memory variables.
• You can use ReadFloat and WriteFloat to interface with the user.
• You can add a P in the instruction to pop a value off the stack.
• You can use an I in the instruction to convert an integer number to a floating point
number before pushing it to the stack (FILD, FIADD...)
• You can use FFREE ST(i) to free the value at ST(i).
• To make sure your FPU stack is empty, use the ShowFPUStack function.
The Absolute Value Floating Point Printer. Create a program to prompt for a floating-point
value. Once it is on the FPU stack, Compare the number to zero. If it is less, use the FCHS
instruction to change the sign of the number and print it. If the number is greater or equal to
zero, simply print it. You are NOT allowed to use the FABS instruction. You will receive a grade of
zero for this question if you do. Follow the hints in the previous part for this part too. You must
show the FPU stack at the end. -1 mark for a non-empty FPU stack.
FPU comparison order:
FCOM
FNSTSW AX
SAHF
Then, use the UNSIGNED conditional jumps (JA, JB etc.)