News:

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

Main Menu

using & in equates

Started by StillLearningMasm, August 07, 2022, 03:11:19 PM

Previous topic - Next topic

StillLearningMasm

I now have a better understanding of equates.

I have a couple of questions in the following code fragments that  are using equates with & for text substitution.
Below is the code fragment:

var1 equ v1
var3 equ v3
v1v3 equ v3
%v3 equ var1&var3
%v1v2d equ &var3


This is the listing file of this code using MASM:

= v1 var1 equ v1
= v3 var3 equ v3
= v3 v1v3 equ v3
= v1v3 %v3 equ var1&var3
%v1v2d equ &var3 ;error error A2123: text macro nesting level too deep


first question:
Why is the text value created by %v3 equ var1&var3
= v1v3.  When I expected it to be further reduced to v3.
process I believe being used should be this:
%v3 equ var1&var3 -> v1v3 -> v3
Is this not done because the result ends with v3?

second question
Is the text value created by %v1v2d equ &var3
- error caused by circular reference?
process I believe being used is this:
%v1v2d equ &var3 -> v3 -> v1v3 -> v3 (is circular reference)

Why doesn't the first question result to error by circular reference?
I assume it is because it does not reduce to v3

Thank you for any help.

HSE

Hi SL!

You only use "&" inside macros to link macro arguments with text or other argument:m1 macro a1, a2, a3
   a1&a2 = a3 *10
   variable&a2 = a3
   function&a1&decimal = a3 *1000
endm


Outside macros you can use CATSTR or @CatStr()@CatStr(v1,v2,<d>) equ @CatStr(var1,var3)

Regards, HSE
Equations in Assembly: SmplMath

StillLearningMasm

Thank you for a response HSE,

Actually "&" does not require the usage to be only in a macro.
It can be within a equate as long as the type of the equate results in a text macro AND
it requires a % to be before the variable name being defined by the equate.

For example:

var1 equ v1
var3 equ v3
v1v3 equ v3
%v3 equ var1&var3 ;notice a % is before the variable name this results in the variable named v3
                              ;being equated to v1v3. The & causes a substitution of var1 and var3. if the
                              ;% did not exist then the variable name v3 would be equated to var1&var3.
                             ;If var1 was equated to a number then the result of the equate for v3 would
                             ;be var1&v3 because & is being used to replace a number. This is not allowed
                             ;only text can be replaced by using &.
                            ;Var1 could be equated to a number but it would require this form of the equate
                           ;instruction:
                           ;var1 equ <5> ;notice the <> this results in 5 being a text value of 5 and not a
                          ; number of 5. The result for the equate for v3 would then be v1v3.