; Listing3-7.asm ; ; A program that demonstrates caling the math_cos ; and math_csc functions. option casemap:none ; Include the aoalib (ANSI strings) and aoamath ; libraries: include aoalib.inc include math.inc includelib aoalib.lib includelib aoamath.lib .const ; Program title: align word ttlStr byte "Listing 3-7", 0 .data align 16 aVal real8 ? mtwo real8 -2.0 aResult real8 0.0 piBy16 real8 16.0 .code ; External definitions for C/C++ cos function externdef cos:proc ; Here is the main assembly language function. public asmMain asmMain proc push rbx sub rsp, 64 ;Shadow storage + alignment fldpi ;Set aVal to pi/2 fld mtwo fdivp fstp aVal fldpi fld piBy16 fdivp fstp piBy16 call print byte "(x)=(ASM.cos(x),ASM.csc(x)); (C.cos(x),C.csc(x))", nl, 0 ; Repeat for aVal = -pi/2 to +pi/2 by pi/32: mov rbx, 17 pgmLoop: ; Compute the assembly language cos result: math(cos) aVal fstp aResult mov rdx, aVal mov r8, aResult call print byte "(%4.1f)=(%10.3e,", 0 ; Compute the assembly language csc result: fld aVal call math_csc fstp aResult mov rdx, aResult call print byte "%10.3e);", 0 ; Use C++ cos: movsd xmm0, aVal call cos movsd aResult, xmm0 ; Print the C cos result: mov rdx, aResult call print byte " (%10.3e,", 0 ; Compute and display C csc result; fld aResult fld1 fdivrp fstp aResult mov rdx, aResult call print byte "%10.3e)", nl, 0 nextIteration: fld piBy16 fld aVal faddp fstp aVal dec rbx jnz pgmLoop allDone: add rsp, 64 pop rbx ret ;Returns to caller asmMain endp end