The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: nibbleNbits on December 24, 2011, 04:41:53 AM

Title: logs : anti-log
Post by: nibbleNbits on December 24, 2011, 04:41:53 AM
; 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
Title: Re: logs : anti-log
Post by: dedndave on December 24, 2011, 04:48:43 AM
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
Title: Re: logs : anti-log
Post by: nibbleNbits on December 24, 2011, 04:57:34 AM
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
Title: Re: logs : anti-log
Post by: raymond on December 24, 2011, 05:09:46 AM
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.
Title: Re: logs : anti-log
Post by: dedndave on December 24, 2011, 05:17:35 AM
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
Title: Re: logs : anti-log
Post by: nibbleNbits on December 24, 2011, 05:23:57 AM
Thanks for your help, I will take a look at it.

by the way Merry Chistmas

Title: Re: logs : anti-log
Post by: nibbleNbits on December 24, 2011, 08:26:28 PM
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