News:

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

Main Menu

another question about macro's.

Started by gelatine1, October 22, 2015, 10:45:40 PM

Previous topic - Next topic

gelatine1

So this question is about some %echo that's acting weird and I don't know why. I have the 2 small macro's below:


FLT4 MACRO float_number:REQ ;taken from siekmanski ;)
LOCAL float_num
.data
align 4
float_num real4 float_number
.code
EXITM <float_num>
ENDM

ech MACRO vars:VARARG
LOCAL temp
FOR item, <vars>
temp TEXTEQU FLT4(item)
%echo item
%echo temp
    ENDM
ENDM


If i try to use these macro's as follows:


ech(1.0)
%echo FLT4(1.0)


then I get this as output while assembling:


(1.0)
??001A
??001B

real4.asm(103) : error A2187: must use floating-point initializer
FLT4(4): Macro Called From
  MacroLoop(0): iteration 1: Macro Called From
   ech(6): Macro Called From
    real8.asm(103): Main Line Code


As far as I know I never call something similar to FLT4(4) and I don't understand the meaning of those ??001x. And how should I echo the DWORD value representing 1.0 in Real4 format ? because all my attempts have failed so far..

Thanks in advance

mabdelouahab


jj2007

The ??001A are labels and variables generated for local use by the macro. You can "visualise" them with the % operator. See the guide for macro expansion operator.

gelatine1

Quote from: mabdelouahab on October 22, 2015, 11:33:36 PM
Try

ech 1.0
%echo FLT4(1.0)


Didn't make any difference :/

Quote from: jj2007 on October 22, 2015, 11:58:34 PM
The ??001A are labels and variables generated for local use by the macro. You can "visualise" them with the % operator. See the guide for macro expansion operator.

So I had read about this expansion operator (the % sign) (on http://www.sxlist.com/techref/language/masm/masmc09.htm) and I tried it out (maybe I am doing something wrong ?) but it doesn't work either... this is my new code and my new output:


ech MACRO vars:VARARG
LOCAL temp
FOR item, <vars>
temp TEXTEQU FLT4(item)
% echo temp
% echo %temp
% echo %(temp)
echo temp
echo %temp
echo %(temp)
    ENDM
ENDM



??001A
%??001A
%(??001A)
??0019
%??0019
%(??0019)

qWord

What should the output show? Your macro does return an anonym label, so the output is correct.
MREAL macros - when you need floating point arithmetic while assembling!

gelatine1

I'd like to see this: 0 01111111 00000000000000000000000b (or 3F800000h in hex notation or in decimal ofcourse)

I've also tried this now:

ech MACRO vars:VARARG
LOCAL temp
FOR item, <vars>
temp TEXTEQU %(FLT4(item))
% echo temp
    ENDM
ENDM

ech 1.0


but that gave the following output while assembling:


real4.asm(89) : error A2026: constant expected
MacroLoop(1): iteration 1: Macro Called From
  ech(5): Macro Called From
   real8.asm(89): Main Line Code
0

qWord

Quote from: gelatine1 on October 23, 2015, 04:58:09 AM
I'd like to see this: 0 01111111 00000000000000000000000b (or 3F800000h in hex notation or in decimal ofcourse)
That's impossible with MASM, because you can't read from segments while assembling.
MREAL macros - when you need floating point arithmetic while assembling!

Zen

Quote from: QWORD...because you can't read from segments while assembling.
...I didn't know that,...:icon_eek:
In fact,...I know so little about writing macros, it's pathetic,...

gelatine1

Quote from: Zen on October 23, 2015, 05:28:57 AM
Quote from: QWORD...because you can't read from segments while assembling.
...I didn't know that,...:icon_eek:
In fact,...I know so little about writing macros, it's pathetic,...

Well .. me neither :o But I already have another small question...


.data
align 4
fl1 REAL4 1.0
fl0 REAL4 0.0
flm1 REAL4 -1.0

FLT4 MACRO float_number:REQ
LOCAL float_num,temp
temp TEXTEQU <1.0>
IF (float_number TEXTEQ temp) ;some frequent cases to save memory
EXITM fl1
ENDIF
ENDM

push FLT4(1.0)


Why does the above code give me the following error ?


real4.asm(108) : error A2050: real or BCD number not allowed
FLT4(3): Macro Called From
  real4.asm(108): Main Line Code
real4.asm(108) : error A2008: syntax error : in instruction

mabdelouahab

FLT4 MACRO float_number:REQ
temp SUBSTR  <float_number> ,1,3
IFIDN temp,<1.0>
EXITM <fl1>
ENDIF
IFDIF temp,<1.0>
EXITM <0> ; <---- do anyting else
ENDIF
ENDM

gelatine1

Quote from: mabdelouahab on October 23, 2015, 05:50:49 PM
FLT4 MACRO float_number:REQ
temp SUBSTR  <float_number> ,1,3
IFIDN temp,<1.0>
EXITM <fl1>
ENDIF
IFDIF temp,<1.0>
EXITM <0> ; <---- do anyting else
ENDIF
ENDM


I don't understand why that SUBSTR Is necessary? And what if the user passed 1.056 for example?  your code would return fl1 which is not correct

qWord

Quote from: gelatine1 on October 23, 2015, 05:28:35 PM
IF (float_number TEXTEQ temp) ;some frequent cases to save memory

Why does the above code give me the following error ?
Because you invented new syntax elements which MASM is not aware of.

From your previous posts I deduce that you want to avoid redundant floating point constants in memory(?). To do so, you need to record the FP literals to compare them:
gfl_glb_cntr = 0
GET_REAL4_CONST macro lit
LOCAL lbl

grc_const_found = 0
grc_cntr = 0
WHILE grc_cntr LT gfl_glb_cntr
% IFIDN <&lit>,<@CatStr(<const_flt__>,%grc_cntr)>
grc_const_found = -1
EXITM
ENDIF
grc_cntr = grc_cntr + 1
ENDM
IF grc_const_found EQ 0
.const
lbl REAl4 lit
.code
@CatStr(<const_flt__>,%gfl_glb_cntr) TEXTEQU <&lit>
@CatStr(<const_flt_lbl__>,%gfl_glb_cntr) TEXTEQU <lbl>
gfl_glb_cntr = gfl_glb_cntr + 1
EXITM <lbl>
ELSE
EXITM @CatStr(<const_flt_lbl__>,%grc_cntr)
ENDIF
endm

With more macro power this method could be improved, e.g. by transforming the decimal numbers into a canonical form (123.456 -> 1.23456E2)
MREAL macros - when you need floating point arithmetic while assembling!

gelatine1

Yes I would like to avoid redundant floating point constants in memory. I have read your code but I don't really understand these lines:


const
lbl REAl4 lit
.code
@CatStr(<const_flt__>,%gfl_glb_cntr) TEXTEQU <&lit>
@CatStr(<const_flt_lbl__>,%gfl_glb_cntr) TEXTEQU <lbl>


What is the meaning of the & before lit? And what's the difference between the constflt and the constfltlbl?  And are they global variables or something?

GoneFishing

Quote from: qWord on October 23, 2015, 09:39:03 PM
...
From your previous posts I deduce that you want to avoid redundant floating point constants in memory(?).
...

Could you please clarify why "floating point constants in memory" are redundant ?
Comes to memory when Japheth called COM atavistic technology .

qWord

Quote from: GoneFishing on October 24, 2015, 08:38:17 AMCould you please clarify why "floating point constants in memory" are redundant ?

.const
x REAL4 1.0
y REAL4 1.0
z REAL4 1.0
MREAL macros - when you need floating point arithmetic while assembling!