; Listing3-5.asm
;
; A program that demonstrates caling the math_asin
; 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:

            align   word
ttlStr      byte    "Listing 3-5", 0


            .data
            align   16
aVal        real8   -2.0
one         real8   1.0
zero        real8   0.0
aResult     real8   0.0
point5      real8   0.25


            .code

; External definitions for C/C++ atan function

            externdef asin:proc
        
; Here is the main assembly language function.

            
            public  asmMain
asmMain     proc
            push    rbx
            sub     rsp, 64 ;Shadow storage + alignment
            
; Repeat for aVal = -4.0 to +4.0 by 0.5:

            mov     rbx, 17
pgmLoop:

; Compute the assembly language result:

            math(asin) aVal
            fstp    aResult
            mov     rdx, aVal
            mov     r8, aResult
            call    print
            byte    "ASM.asin(%4.1f)=%6.3f  ", 0
            
; Use C++ asin:
             
            movsd   xmm0, aVal
            call    asin
            
; Print the C result:

            movsd   aResult, xmm0
            mov     rdx, aVal
            mov     r8, aResult
            call    print
            byte    "C.asin(%4.1f)=%6.3f", nl, 0
            jmp     nextIteration

; Drop down here if we tried to take the square root
; of a negative number or divide by zero:
            
badSqrt:    mov     rdx, aVal
            call    print
            byte    "C.asin(%4.1f)= -nan", nl, 0
            
nextIteration:
            fld     point5
            fld     aVal
            faddp
            fstp    aVal
            dec     rbx
            jnz     pgmLoop
            
            
 
allDone:    add     rsp, 64
            pop     rbx
            ret     ;Returns to caller
        
asmMain     endp
            end