Author Topic: macro issue (using SmplMath)  (Read 1551 times)

HSE

  • Member
  • ****
  • Posts: 545
  • <AMD>< 7-32>
macro issue (using SmplMath)
« on: February 13, 2016, 02:57:34 AM »
Hi!

 I have had a brillant idea to simplify equations:

Code: [Select]
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

qWord

  • Member
  • *****
  • Posts: 1469
  • The base type of a type is the type itself
    • SmplMath macros
Re: macro issue (using SmplMath)
« Reply #1 on: February 13, 2016, 03:41:33 AM »
such  text macros cause endless recursion on expansion. Simple test case:
Code: [Select]
A TEXTEQU <A>
A

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

HSE

  • Member
  • ****
  • Posts: 545
  • <AMD>< 7-32>
Re: macro issue (using SmplMath)
« Reply #2 on: February 13, 2016, 11:29:35 AM »
Thanks qWord :t

I change the variable name in the object  instead:
Code: [Select]
DefineR8 macro nombre , valor
DefineVariable @CatStr( R8_ , &nombre) , REAL8 , &valor
&nombre textequ @CatStr( [esi].R8_ , &nombre)
endm
and the code look very clean now:
Code: [Select]
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):
Code: [Select]

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


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

Code: [Select]
DefineR8 macro nombre , valor
        local name1
DefineVariable @CatStr( R8_ , &nombre) , REAL8 , &valor
name1 = @CatStr( [esi].R8_ , &nombre)
         &nombre textequ name1
endm
« Last Edit: February 13, 2016, 12:57:18 PM by HSE »

qWord

  • Member
  • *****
  • Posts: 1469
  • The base type of a type is the type itself
    • SmplMath macros
Re: macro issue (using SmplMath)
« Reply #3 on: February 13, 2016, 04:39:24 PM »
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:
Code: [Select]
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.


there is a problem (perhaps with DefineVariable):
Code: [Select]
: 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:
Code: [Select]
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

  • Member
  • ****
  • Posts: 545
  • <AMD>< 7-32>
Re: macro issue (using SmplMath)
« Reply #4 on: February 14, 2016, 04:18:06 AM »
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.
Code: [Select]
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 ¿?

HSE

  • Member
  • ****
  • Posts: 545
  • <AMD>< 7-32>
Re: macro issue (using SmplMath)
« Reply #5 on: February 14, 2016, 05:38:01 AM »
I'm replying to myself  8).

All that noise because a little "space"?

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