MASM C Format Range byte, db char 8 bits, 2's complement -128 to 127 word, dw short 16 bits, 2's complement, little endian -32768 to 32767 dword, dd int, long 32 bits, 2's complement, little endian -2147483648 to 2147483647 qword, dq long long 64 bits, 2's complement, littlen endian +- 9223372036854775808 real4 float sign, 8 bit exponent, 23 bit mantissa, implied 1 +- 1.7e38, 6 significant digits real8 double sign, 11 bit exp, 52 bit mant, implied 1 +- 1e308, 14 significant digits tbyte, dt long double sign, 15 bit exp, 64 bit, explicit leading 1 +- 1e4932, 18 significant digitsFloating point values can also be +infinity, -infinity, or NaN (not a number).
Status word +----------+ +--------------------------------------------+ | ST | <-- top of stack |B C3 TOS C2 C1 C0 ES SF PE UE OE ZE DE IE | +----------+ +--------------------------------------------+ | ST(1) | 15 14 13-11 10 9 8 7 6 5 4 3 2 1 0 +----------+ ... +--------------------------------------------+ +----------+ |X X X X RC PC X X PM UM OM ZM DM IM | | ST(7) | +--------------------------------------------+ +----------+ 15-12 11-10 9-8 7 6 5 4 3 2 1 0 Stack of 80-bit (tbyte) values Control word Registers are marked as used, empty, or invalid. Status word: B = busy (not used for on-chip FPU) C3 = compare equal (zero flag) TOS = top of stack (000-111) C2 = comparison undefined (parity flag) C1 = negative C0 = compare less than (carry flag) ES = error summary (one or more bits below are set) SF = stack overflow/underflow PE = precision UE = underflow OE = overflow ZE = zero divide DE = denormalized IE = invalid Control word: X = reserved, do not use RC = round control: 00 = nearest (even if tie), 01 = down, 10 = up, 11 = to zero PC = precision control: 00 = real4, 10 = real8, 11 = tbyte (default) PM, UM, OM, ZM, DM, IM = don't interrupt if corresponding fault occurs
fld x ; push real4, real8, tbyte, convert to tbyte fild x ; push word, dword, qword, convert to tbyte fst x ; convert ST and copy to real4, real8, tbyte fist x ; convert ST and copy to word, dword, qword fstp x ; convert to real and pop fistp x ; convert to integer and pop fxch st(n) ; swap with st(0)Qword integer operands are only valid for load and store, not arithmetic.
fadd ; add st(0) to st(1) and pop (result now in st(0)) fadd st, st(n) ; add st(1)-st(7) to st(0) fadd st(n), st ; add st(0) to st(1-7) faddp st(n), st ; add to st(n) and pop fadd x ; add real x to st fiadd x ; add integer word or dword x to st ; operands are like fadd, faddp, fiadd fsub, fisub ; subtract real, integer fsubr, fisubr ; subtract in reverse: st(1) = st-st(1), pop fmul, fimul ; multiply fdiv, fidiv ; divide fdivr, fidivr ; divide in reverse fsubp, fsubrp, fmulp, fdivp, fdivrp ; pop like faddp ; No explicit operands, result is put in st ; push constants fldz ; push 0 fld1 ; push 1 fldpi ; push pi fldl2e ; push log2(e) fldl2t ; push log2(10) fldlg2 ; push log10(2) fldln2 ; push ln(2) ; replace st with result fabs ; st = abs(st) fchs ; st = -st frndint ; round to integer (depends on rounding mode) fsqrt ; square root fcos ; cosine (radians) fsin ; sine fsincos ; sine, then push cosine fptan ; tangent fpatan ; st(1) = arctan(st(1)/st), pop ; Can be combined to compute exponents fxtract ; pop st, push exponent, mantissa parts fscale ; st *= pow(2, (int)st(1)) (inverse of fxtract) f2xm1 ; pow(2, st) - 1, -1 <= st <= 1 fyl2x ; st(1) *= log2(st), pop fyl2xp1 ; st(1) = st(1) * log2(st) + 1, pop
fcom x ; compare (operands like fadd), set flags C0-C3 fnstsw ax ; copy flags to AX sahf ; copy AH to flags ja, je, jne, jb ; test CF, ZF flags as if for unsigned int compare fcomp, fcompp ; compare and pop once, twice ficom x ; compare with int ficomp ; compare with int, pop fcomi ; compare, setting CF, ZF directly (.686) fcomip ; compare direct and pop (.686) fucom, fucomp, fucompp; compare allowing unordered (NaN) without interrupt fucomi, fucomip ; compare setting CF, ZF, PF directly (.686) jp ; test for unordered compare (parity flag) ftst ; compare st with 0
fninit ; empty stack, mask exceptions, set default rounding to nearest fnstcw x ; store control word in word x mov ax, x ; default value is 037fh or ax, c00h ; set rounding control to round to 0 (as in C) mov x, ax fldcw x ; load control word
Material prepared for CSE 3101 by Matt Mahoney, Oct. 25, 2004.