Tutorial: Printing FPU Floating Numbers in Pure Assembly
Posted: Fri Feb 10, 2017 8:36 pm
Link (Public Domain License):
http://devel.archefire.org/forum/viewto ... l=en#p4143
EXE:
http://devel.archefire.org/tmp/FPU_float_print_demo.zip
http://archive.org/download/x86_FPU_Pro ... t_demo.zip
Video description:
http://www.youtube.com/watch?v=Xrfri-hKYbg
This is a tutorial with a sample Win32 program and Assembly utility functions that convert a floating point number from the FPU to print it. The function uses the FPU itself to convert each digit into ASCII, first the integer part and then the floating point part.
It also has an ASCII string reversion utility function since the integer string representation is generated backwards. The function reads the first and last character at a time in AL and AH respectively, then uses XCHG and writes them back to revert the string as if we flipped a transparent sheet and could see the string values already reverted. Then it increases the start of string pointer and decreases the end of string pointer to continue the reversion. If the string has odd size or if it reached the last two bytes (size divided by 2 in the function), it will stop because it makes no sense to try to revert the center byte, for example, in a 3-byte string.
I have put it in my external website since I have full control there to edit the HTML, the links and maintain it properly. I put it here since I realize that it will be an useful snippet to actually learn how to finally use the FPU usefully by being able to calculate and then print the results right away to know whether we calculated correctly.
http://devel.archefire.org/forum/viewto ... l=en#p4143
EXE:
http://devel.archefire.org/tmp/FPU_float_print_demo.zip
http://archive.org/download/x86_FPU_Pro ... t_demo.zip
Video description:
http://www.youtube.com/watch?v=Xrfri-hKYbg
This is a tutorial with a sample Win32 program and Assembly utility functions that convert a floating point number from the FPU to print it. The function uses the FPU itself to convert each digit into ASCII, first the integer part and then the floating point part.
It also has an ASCII string reversion utility function since the integer string representation is generated backwards. The function reads the first and last character at a time in AL and AH respectively, then uses XCHG and writes them back to revert the string as if we flipped a transparent sheet and could see the string values already reverted. Then it increases the start of string pointer and decreases the end of string pointer to continue the reversion. If the string has odd size or if it reached the last two bytes (size divided by 2 in the function), it will stop because it makes no sense to try to revert the center byte, for example, in a 3-byte string.
I have put it in my external website since I have full control there to edit the HTML, the links and maintain it properly. I put it here since I realize that it will be an useful snippet to actually learn how to finally use the FPU usefully by being able to calculate and then print the results right away to know whether we calculated correctly.