SetPrecisionEx function
The SetPrecisionEx function sets the number of digits after the point for floating-point output. The parameter is passed through the stack. The function automatically aligns the stack to 2 bytes.
Parameters (stack): 1. Number of digits after the decimal point.
Return value: The function does not return a value.
Flag state: The function does not modify the flags.
Program source code
Intel 8086 assembly program example demonstrating the use of the SetPrecisionEx function to set the precision of floating-point output.
title .286C .model small .stack 100h data segment public fmtout db "%f + %f = %f\0" number1 dq 23.4562 number2 dq 51.6847 data ends code segment public assume ds:data, cs:code include Handyfar.inc ; Include the file with functions include Handymac.inc ; Include the file with macros main proc call SetDataSegment ; Call the SetDataSegment procedure push 3 ; Push the number 3 onto the stack call SetPrecisionEx ; Call procedure SetPrecisionEx(3) fld qword ptr[number1] ; Push number1 onto the math coprocessor stack fadd qword ptr[number2] ; number1 + number2 (the result stays on top of the math stack) fld qword ptr[number2] ; 3rd: Load number2 onto the math coprocessor stack fld qword ptr[number1] ; 2nd: Load number1 onto the math coprocessor stack leaax ds:[fmtout] ; 1st: Load the address of format string fmtout into register ds:ax call PrintFormatString ; Call procedure PrintFormatString(ax:fmtout, ...) push 0 ; Push the byte return code onto the top of the stack call ExitProcessEx ; Call the ExitProcessEx(0) procedure main endp code ends end main
23.456 + 51.684 = 75.140
Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".