The MASM Forum

General => The Campus => Topic started by: gmmo1971 on February 07, 2013, 11:14:47 AM

Title: loading into the FPU an indexed variable.
Post by: gmmo1971 on February 07, 2013, 11:14:47 AM
I am looking at the fld instruction and it takes memory location.

fld myVar

I have an array

myVar            REAL4   ?

what is the best way to load these values into the FPU?

thx!
Title: Re: loading into the FPU an indexed variable.
Post by: gmmo1971 on February 07, 2013, 11:16:58 AM
correction I meant

myVar      REAL4   4 DUP (-2.)

want to load these for values into fpu registers.

the fld only lets me do a memory location. Can I do indexed?

thx.
Title: Re: loading into the FPU an indexed variable.
Post by: Gunther on February 07, 2013, 11:36:56 AM
Hi gmmo1971,

sure. Load a CPU register with the start address of your array, load the first element into the FPU stack, adjust your pointer register (add 4) and load the next array element. That's all.

Gunther
Title: Re: loading into the FPU an indexed variable.
Post by: qWord on February 07, 2013, 11:44:37 AM
A short example:myVar REAL4 1.0,2.0,3.0
result REAL4 ?
...
fld myVar[0*SIZEOF REAL4]
fld myVar[1*SIZEOF REAL4]
; ST(0) = 2.0 , ST(1) = 1.0

; for example: use register only
fmulp st(1),st ; st(1) = st(1)*st(0) = 1*2 -> pop stack
; st(0) = 1*2

; for example: use memory operand
fmul myVar[2*SIZEOF REAL4] ; st(0) = st(0)*myVar[2*SIZEOF REAL4] = 2*3

fstp result  ; save result and pop stack

You may take a look in Intel's or AMD's documentation for further details.
Title: Re: loading into the FPU an indexed variable.
Post by: jj2007 on February 07, 2013, 05:16:55 PM
> Can I do indexed?
Yes.

include \masm32\include\masm32rt.inc

.data
MyR4   REAL4 -2., -1.0, 0.0, 1.0

.code

start:   mov esi, offset MyR4
   xor ecx, ecx
   .Repeat
      fld REAL4 ptr [esi+REAL4*ecx]
      inc ecx
   .Until ecx>=(sizeof MyR4/REAL4)
   inkey "ok"
   exit

end start

Title: Re: loading into the FPU an indexed variable.
Post by: dedndave on February 08, 2013, 02:45:48 AM
you can also use
    mov esi, offset MyR4
    fld REAL4 ptr [esi]
    fld REAL4 ptr [esi+4]
    fld REAL4 ptr [esi+8]
    fld REAL4 ptr [esi+12]

or
    fld     MyR4
    fld     MyR4+4
    fld     MyR4+8
    fld     MyR4+12