News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

macro issue (using SmplMath)

Started by HSE, February 13, 2016, 02:57:34 AM

Previous topic - Next topic

HSE

Hi!

I have had a brillant idea to simplify equations:

bDNAmx textequ @CatStr( [esi]. , bDNAmx )

fSlv8 bDNAmx = 0.112 * [esi].ebwR/650.0 * [esi].ebwm/650.0 ;


I suspect this is triggering an endless loop. There is some way to do that thing?

Thanks. HSE
Equations in Assembly: SmplMath

qWord

such  text macros cause endless recursion on expansion. Simple test case:
A TEXTEQU <A>
A


Rename the text macro, e.g. _bDNAmx.
MREAL macros - when you need floating point arithmetic while assembling!

HSE

#2
Thanks qWord :t

I change the variable name in the object  instead:

DefineR8 macro nombre , valor
DefineVariable @CatStr( R8_ , &nombre) , REAL8 , &valor
&nombre textequ @CatStr( [esi].R8_ , &nombre)
endm

and the code look very clean now:

DefineR8 bDNAmx, 0.0
DefineR8 ebwm, 0.0
DefineR8 ebwR, 650.0;

fSlv8 bDNAmx = 0.112 * ebwR/650.0 * ebwm/650.0 ;


Very nice but there is a problem (perhaps with DefineVariable):


: Error A2118: forced error: PARSER: missing square-bracket: [ or ]



Oh, recurrency again. I'm trying to skip in this way:


DefineR8 macro nombre , valor
        local name1
DefineVariable @CatStr( R8_ , &nombre) , REAL8 , &valor
name1 = @CatStr( [esi].R8_ , &nombre)
         &nombre textequ name1
endm

Equations in Assembly: SmplMath

qWord

Your usage of TEXTEQU and @CatStr does look strange and I would recommend you to do it as documented in the MASMs programmers guide (and reference). To give you an idea:
equateID = 123
foo TEXTEQU <my text: >,textMacoID,<, xyz=>,%equateID
; foo is text macro (ID). TEXTEQU and CATSTR are equivalent.
; Function-like version:
... @CatStr(<my text: >,%textMacroID,<, xyz=>,%equateID)

; For your above code, e.g.:
nombre textequ <[esi].R8_>, <&nombre>

; or shorter
nombre textequ <[esi].R8_&nombre>

;The ampersand is used to "mark" macro argument names in ambiguity situations
see the programmers guide for more details.


Quote from: HSE on February 13, 2016, 11:29:35 AM
there is a problem (perhaps with DefineVariable):
: Error A2118: forced error: PARSER: missing square-bracket: [ or ]

I can't reproduce your error (ml6 and 8). Maybe you can extend the following test to reproduce the error:
include \masm32\include\masm32rt.inc
include \macros\SmplMath\math.inc

foo struct
R8_ebwR REAL8 ?
R8_ebwm REAl8 ?
R8_bDNAmx REAL8 ?
foo ends

DefineR8 macro nombre , valor
&nombre textequ @CatStr( [esi].R8_ , &nombre)
endm

.code
main proc


assume esi: ptr foo

DefineR8 bDNAmx, 0.0
DefineR8 ebwm, 0.0
DefineR8 ebwR, 650.0;

fSlv8 bDNAmx = 0.112 * ebwR/650.0 * ebwm/650.0 ;


main endp
end main
MREAL macros - when you need floating point arithmetic while assembling!

HSE

Quote from: qWord on February 13, 2016, 04:39:24 PM
Your usage of TEXTEQU and @CatStr does look strange

Just following the law  :biggrin::

Quote from:  Murphy law
When all other options fail, you must read the manual

The complete example show a problem, but compiler only detect secondary effects.
include \masm32\include\masm32rt.inc
include \masm32\\macros\SmplMath\math.inc

foo struct
R8_ebwR REAL8 650.0
R8_ebwm REAl8 550.0
R8_bDNAmx REAL8 0.0
foo ends

DefineR8 macro nombre , valor
&nombre textequ @CatStr( [esi].R8_ , &nombre)
endm
.data
    FOO foo <>
    gral1 REAL8 0.0
.code
main proc
mov esi, offset FOO   
assume esi: ptr foo

DefineR8 bDNAmx, 0.0
DefineR8 ebwm, 550.0
DefineR8 ebwR, 650.0;

      finit
       
fSlv8 bDNAmx = 0.112 * ebwR/650.0 * ebwm/650.0 ;

       fSlv8 gral1 = bDNAmx

       print( 13, 10, real8$(gral1), 13,10);
       inkey
main endp
end main


I think a option is to create artificial names inside the structure. But I need to be sure the same articial names are created when trying to acces from differents  objects.

Thanks again!

LATER: changing for  "print real8$(gral1),13,10" , work perfectly ¿?
Equations in Assembly: SmplMath

HSE

I'm replying to myself  8).

All that noise because a little "space"?

DefineR8 macro nombre , valor
DefineVariable @CatStr(  < >,R8_ , &nombre ) , REAL8 , &valor
&nombre textequ <[esi].R8_&nombre>
endm

Equations in Assembly: SmplMath