News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

logs : anti-log

Started by nibbleNbits, December 24, 2011, 04:41:53 AM

Previous topic - Next topic

nibbleNbits

; Purpose to return double value y^x
; i.e y^1/3 , y^2/3 etc

.586
.model flat, C
option casemap :none

;---------------------------------------------------------
; double = pow_yx(double y,double x); C++ calling function
;---------------------------------------------------------
.data


.code

pow_yx proc public y:REAL8, x:REAL8
   
   finit
   
   fld1
   fld y
    fyl2x   
    fldl2t   
    fdiv   
    fld x
fmul
   
   ret
   
pow_yx endp

end

dedndave

it looks like you double-posted

Quote; Purpose to return double value y^x

i think you are trying to return y1/x

Ray has a nice FPU tutorial that should be helpful
http://www.ray.masmcode.com/tutorial/index.html

nibbleNbits

yes, I did double post? not sure how but I did. My question is on the second post. I need to return the anti-log value

thanks

raymond

Dave's suggestion is good. However, for your particular objective, it may be faster to look at the source code of the FpuXexpY function of the Fpulib, starting at the dest0: label following the code to "parse" the parameters. Then go back to the tutorial to get more details about the instructions used in that source code.
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

dedndave

of course, you could just take Ray's code and convert it to C calling convention   :P
not sure about how he would feel about that

the key is in his tutorial, ch 11...
yx =2(x log2(y))

not sure about the C compiler, but it is a little tricky to pass qword parameters in ASM

nibbleNbits

Thanks for your help, I will take a look at it.

by the way Merry Chistmas


nibbleNbits

This works, I had mixed my log base before, natural and common logs. I need to do some additiional error trapping but the following works for now.

; Purpose to return double value y^x
; i.e y^1/3 , y^2/3 etc
; i.e y^0.333333..., y^0.66666666.....,

.586
.model flat, C
option casemap :none

;---------------------------------------------------------
; double = pow_yx(double y,double x); C++ calling function
;---------------------------------------------------------
.data


.code

pow_yx proc public y:REAL8, x:REAL8
   
   finit
   
   fld1
   fld y
    fyl2x   
    fld x
   fmul

   fld st(0)
   frndint                 ;keep only the characteristic
   fsub  st(1),st          ;keeps only the mantissa
    fxch                    ;get the mantissa on top

    f2xm1                   ;->2^(mantissa)-1
    fld1
    fadd                    ;add 1 back
   
   fscale                  ;scale it with the characteristic
     
    fstsw ax                ;retrieve exception flags from FPU
    fwait
    shr   al,1              ;test for invalid operation
    jc    srcerr           
   jmp isok
srcerr:
     xor   eax,eax
     ret
isok:                  ; leave return value on stack st(0)
   
   ret
   
pow_yx endp

end