News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Using struct with Fpu

Started by ragdog, August 16, 2013, 04:55:53 PM

Previous topic - Next topic

ragdog

Hi

I use Fpu in my Tool now i want to use a structure to change some variables
exmpl:
szText              db "Test string",0
Num1       REAL4   0.06f
Num2      REAL4   0.2f
Num3       dd      3

My struct is

CalcStruct struct
  pText                dword ?
  fpuNum1         REAL4   ? 
fpuNum1         REAL4   ? 
DDNum1         Dword   ? 

CalcStruct ends

CalcStruct    <offset szText,Num1,Num2,Num3,>

Can any help me or post an example?

Thanks in forward
Greets,

dedndave

;when you define a structure, no data is created
;you are simply describing a new data type
;notice that we have not opened the .CONST, .DATA, .DATA?, or .CODE section

CalcStruct struct
  pText   dd    ?
  fpuNum1 REAL4 ?
  fpuNum1 REAL4 ?
  DDNum1  dd    ?
CalcStruct ends

;now, you want to define data, using that new data type

    .DATA

cs CalcStruct <szText, 1.234, 3.14, 234234>

szText db 'SomeText',0

;now, let's access one of the structure members

    .CODE

    mov     eax,cs.DDNum1    ;EAX = 234234



also, when you use a pointer to a data item as a data operand, the assembler assumes you want the address
i.e.
<szText,....
is the same as
<offset szText,....

ragdog

Thanks dave

But use a dword or byte in a struct is not my problem

How can use  a struct the fpu values and set from a struct to fpu > fadd


dedndave

the assembler knows it's a REAL4 type

    fadd    cs.fpuNum1  ;adds 1.234 to st(0)

what you were doing was trying to access members via the name "CalcStruct"
CalcStruct is essentially a data type
access them via "cs", the name of the data label

    .DATA

cs CalcStruct <szText, 1.234, 3.14, 234234>