; Listing3-1.asm
;
; A program that demonstrates caling the math_acos
; function.

            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 (In Unicode):

            align   word
ttlStr      byte    "Listing 3-1", 0


            .data
            align   16
aVal        real8   -1.0
aResult     real8   0.0
point1      real8   0.1            


            .code

; External definitions for C/C++ acos function

            externdef acos:proc
        
; Here is the main assembly language function.

            
            public  asmMain
asmMain     proc
            push    rbx
            sub     rsp, 64 ;Shadow storage + alignment
            
; Repeat for aVal = -1.0 to +1.0 by 0.1:

            mov     rbx, 21
pgmLoop:

; Compute the assembly language result:

	math(acos) aVal
            fstp    aResult
            mov     rdx, aVal
            mov     r8, aResult
            call    print
            byte    "ASM.acos(%4.1f)=%6.3f  ", 0
            
; Compute the C function result:

            movsd   xmm0, aVal
            call    acos
            movsd   aResult, xmm0
            mov     rdx, aVal
            mov     r8, aResult
            call    print
            byte    "C.acos(%4.1f)=%6.3f", nl, 0
            
            fld     point1
            fld     aVal
            faddp
            fstp    aVal
            dec     rbx
            jnz     pgmLoop
            
            
 
allDone:    add     rsp, 64
            pop     rbx
            ret     ;Returns to caller
        
asmMain     endp
            end