News:

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

Main Menu

more equate questions

Started by StillLearningMasm, March 27, 2023, 10:44:15 AM

Previous topic - Next topic

StillLearningMasm

Is there anybody out there who can answer these questions?

==========================================
Question 1
Can EQU with <> be replaced with TEXTEQU?

partial code example:
Var1 equ <1> ;initial assigned value is text 1
further down in code
Var1 equ <2> ;value is now text 2

replace first occurance with:
Var1 textequ <1>
replace 2nd occurance with:
Var1 textequ <2>
Should I use EQU ONLY when <> is not needed and use TEXTEQU ONLY when <> is needed?

Can EQU that has <> ALWAYS be replaced with TEXTEQU?
==========================================
Question 2
If a EQU variable with the same name is replaced with a different value
that is allowed is there a difference in these forms of the  EQU statements?

This FORM of using EQU:
Var1 EQU <1> ;initial assigned value is text 1
Var1 EQU <2> ;value is still TEXT but is 2

Compared to using this FORM of EQU:
Var1 EQU <1> ;initial assigned value is text 1
Var1 EQU 2 ;valid, no <> exists but is a TEXT value of 2
Both forms have the same result but I would have expected a error with the second form
Why is there no error?
=========================================================
Last question
why do I have a syntax error in both of these examples:

first example:
Var1 equ <1> ;initial assigned value is text 1
%Var1 equ 2 ;masm error: syntax error : integer

second example:
Var1 equ <1> ;initial assigned value is text 1
%Var1 equ <2>;masm error: syntax error : integer

According to the info in the masm manual:
% expands only text macros, not numeric equates or constant expressions.
in both case Var1 is TEXT. it is not a numeric equate or constant expression.
----------------------------------------------------------------------------------------

Thank you




   



HSE

1 - Equ and textequ are different things.

2 - You can not redefine equ.

3 - You have to read what error say.
Equations in Assembly: SmplMath

StillLearningMasm

Thank you HSE for responding.

I believe your answers are wrong based on examples that I have tried.

For the answer to the second question:
If a EQU without <> is used to initially define a value then
its value cannot be changed but if the initial EQU has <> then its value CAN be changed.
Examples:
a equ 1 ;initial assigned value is a whole number
a equ ! ;redefine error (any value, except the initial value, causes this error)

a equ <1> ;initial assigned value is text 1
a equ 2 ;valid, value is changed to text 2

Try it. You will see I am correct.

_japheth

Quote from: StillLearningMasm on March 27, 2023, 10:44:15 AM
Question 1
Can EQU with <> be replaced with TEXTEQU?

Yes. TEXTEQU was included to reduce Masm's 5.1 "EQU-mess".

Quote
Should I use EQU ONLY when <> is not needed and use TEXTEQU ONLY when <> is needed?

That's a good idea.

Quote
Can EQU that has <> ALWAYS be replaced with TEXTEQU?

I'd say yes, but with Masm you can never be totally sure...

Quote
Question 2
If a EQU variable with the same name is replaced with a different value

Actually, EQU ( without <>) is meant to define a constant, not a variable. However, EQU with <> defines a "text macro", and that is always a variable - really confusing...

Quote
Var1 EQU <1> ;initial assigned value is text 1
Var1 EQU <2> ;value is still TEXT but is 2

Compared to using this FORM of EQU:
Var1 EQU <1> ;initial assigned value is text 1
Var1 EQU 2 ;valid, no <> exists but is a TEXT value of 2
Both forms have the same result but I would have expected a error with the second form
Why is there no error?

A very good question. The first occurance of EQU will set the symbol type - in this case it's a "text macro", so any redefinitions are accepted even without <>. Might actually work just be chance...

Quote
Last question
why do I have a syntax error in both of these examples:

first example:
Var1 equ <1> ;initial assigned value is text 1
%Var1 equ 2 ;masm error: syntax error : integer

According to the info in the masm manual:
% expands only text macros, not numeric equates or constant expressions.
in both case Var1 is TEXT. it is not a numeric equate or constant expression.

The problem is that the symbol name is expanded in this case, translating "Var1 equ <1>" to "1 equ <1>", and that is not accepted.


Dummheit, gepaart mit Dreistigkeit - eine furchtbare Macht.

HSE

Quote from: StillLearningMasm on March 28, 2023, 03:47:40 AM
You will see I am correct.

:biggrin: doesn't matter. Without simple rules, You will end up with a mess.
Equations in Assembly: SmplMath