News:

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

Main Menu

Error messages given from using different equates (EQU and =)

Started by StillLearningMasm, March 15, 2022, 01:22:17 PM

Previous topic - Next topic

StillLearningMasm

When creating code using the different equates available by using MASM v6.1 I have different error messages returned.
The Redefinition error I understand but the other other ones that I get I do not understand. Here are some program
fragments with the error created by the assembler. The error message is below the instruction that caused it:

Here is the first one:

cseg segment
start:
.386
nd equ <1>
;other code goes here
nd = 2
c:\masm32\bin\assembly5.asm(5) : error A2008: syntax error : integer
;other code goes here
cseg ends
end start

Since a error message is given it is in error. IS this a redefine error???
If it is WHY does it not say so?

Here is another example:

cseg segment
start:
.386
nb equ <@FileCur>
;other code goes here
nb = "1.3"
error : only white space or comment can follow backslash
;other code goes here
cseg ends
end start

Notice that the error message has nothing to do with the problem.
So where is it I can find information about EQU,TEXT and =? Not
from Microsoft that is for sure.

Thanks for any info,
StillLearningMasm

_japheth


With the line

nd equ <1>

you did actually define a text macro. That means, further occurrences of the string "nd" were replaced by "1", resulting in line "nd = 2" to be changed to "1 = 2". Hence the apparently strange error msg.
Dummheit, gepaart mit Dreistigkeit - eine furchtbare Macht.

StillLearningMasm

Thank you for a response _japheth.

I thought that the instruction process was this:

nd equ <1>

did this:

create a equated variable.
since "<>" are being used it is to be a text type of variable.
variable value can change because it is a text type.
Since the expression inside the "<>" results in a integer change the type to integer.

later in the code the following instruction:
nd = 2

does this:
variable name already exists and can be changed because it was initially a text type
Variable value has changed. which is allowed. so no error.

So if this process is wrong then what is wrong in this process?
I know i can change the initial EQU to a "=" and that works correctly but
I want to know what I have wrong so I can understand why a EQU variable can not
be changed to a equate variable that uses "=" change its value. NO information
is described about this anywhere that I can find.

Thank you for any help.




_japheth

Quote from: StillLearningMasm on March 15, 2022, 03:04:39 PM
create a equated variable.
since "<>" are being used it is to be a text type of variable.
variable value can change because it is a text type.

Well, yes. Better call this type of variable a "text macro" - that's the name it was assigned originally.
However, it must be added that to change the value of a text macro, you must use the EQU (for "historical reasons) or, better, the TEXTEQU directives.

The '=' directive is restricted to so-called assembly time variables, that must always be of numeric type.

The EQU directive "should" preferably be used only to define numeric constants (that is, used without angle brackets and containing a "valid expression"). Generally, EQU as used in masm is in a somewhat "unlucky" state, because it is not always obvious what a "valid expression" is - and if it isn't, masm converts it "silently" to a text macro.


Dummheit, gepaart mit Dreistigkeit - eine furchtbare Macht.

jj2007

It's confusing. Here is a snippet showing what is possible:

include \masm32\include\masm32rt.inc

.code
start:
  cls
  mov eax, 123
  nd equ eax ; equate without brackets
  print str$(nd), " is the value of nd", 13, 10
  xd equ <111> ; equate with <brackets>
  print str$(xd), " is the value of xd", 13, 10
  xz=11111 ; assembly time numeric variable
  print str$(xz), " is the value of xz", 13, 10

  nd equ 456
  xd equ <222>
  print str$(xd), " is the value of xd", 13, 10
  xz=22222
  print str$(xz), " is the value of xz", 13, 10
  MsgBox 0, cat$(str$(nd), " is the value of nd"), chr$("Hello"), MB_OK

  exit

end start

HSE

First case is an integer, just make:nd = 1
;other code goes here
nd = 2


Second case is an string:
nb textequ <@FileCur>
;other code goes here
nb textequ <1.3>
Equations in Assembly: SmplMath

StillLearningMasm

 _japheth in your post you said this:
Quote
you did actually define a text macro. That means, further occurrences of the string "nd" were replaced by "1", resulting in line "nd = 2" to be changed to "1 = 2". Hence the apparently strange error msg.

I am trying to understand why a comparison was done to "nd". The the first case "nd"  becomes a text type (text macro) then it becomes a integer.
Is that process wrong?
later "nd" is changed from a integer value of 1 to a integer value of 2. Why is there a error message? In both cases they are integer so why does the assembler give a error?

Also, since a error message is given why is it not a redefine error, which actually tells you something?

_japheth

Quote from: StillLearningMasm on March 16, 2022, 03:06:10 AM
I am trying to understand why a comparison was done to "nd". The the first case "nd"  becomes a text type (text macro) then it becomes a integer.
Is that process wrong?

Your understanding is not correct. A symbol's type is assigned when that symbol is defined and it cannot be changed later.

Quote
later "nd" is changed from a integer value of 1 to a integer value of 2. Why is there a error message? In both cases they are integer so why does the assembler give a error?

No. You're trying to change the value of nd from <1> to 2, that is, from a text to a number - and that cannot be done.
Dummheit, gepaart mit Dreistigkeit - eine furchtbare Macht.

hutch--

If you wish to change it, use a memory operand.

.data?
  MyVar dd ?

.code
  mov MyVar, 1234

jj2007

Quote from: hutch-- on March 16, 2022, 05:40:20 PM
If you wish to change it, use a memory operand.

Or use a numeric variable, see xz= in my example above. Caution, this is an assembly time variable, it's value is determined solely by its position in the code.

StillLearningMasm

Thanks everybody for the info. I now have a better understanding of EQU compared to "=".

I still have a question.

program fragment:
cseg segment

start:
.386

rr equ <1>
;other code
rr = 1  ;error A2008: syntax error: integer

;other code
rj equ 1
;other code
rj = 2  ;error A2005:symbol redefinition: rj

;other code
re equ 1
;other code
re = 1  ;no error. Error expected because of change from EQU to "="


cseg ends
end start

Each one has EQU being used to define a integer value of 1.
When rr is being defined it is a text macro of 1 next
rr is being defined a integer value of 1.
This causes a integer error as expected.
(but in reality is a redefinition error)

In the next process
When rj is being defined it is a integer value of 1 next
rj is being defined a integer value of 2.
This causes a redefinition error as expected.

Here in the last example
When re is being defined it is a integer value of 1 next
re is being defined a integer value of 1.
No redefine error occurs. However the initial value for
re was created by EQU but the next value was created by "=".
I thought a EQU could not be redefined unless it was using "<>"
for the initial definition of the equate. Also what is the rule for
combining the usage of a EQU and a "="?

Also, from the different tests that I have done a EQU with <>
is exactly the same as a TEXTEQU.

Why have 2 different reserved words?

Thanks for your help.





_japheth

Quote from: StillLearningMasm on March 17, 2022, 04:01:43 PM
When re is being defined it is a integer value of 1 next
re is being defined a integer value of 1.
No redefine error occurs. However the initial value for
re was created by EQU but the next value was created by "=".
I thought a EQU could not be redefined unless it was using "<>"
for the initial definition of the equate.

That's a good question. I don't know what the developers at MS in the 1980s had in mind when they allowed this variant, but I guess it was for conveniance.
In large projects with lots of files, a constant might be defined multiple times, and there are programmers that prefer '=' and others that prefer EQU to define a "constant".
As long as the value of the symbol is the same, there's no problem.

However, what must NOT be allowed is this, for example:

rr equ 1
rr = 1
rr = 2


In other words: a constant originally defined with EQU must not change its value

Quote
Also, from the different tests that I have done a EQU with <>
is exactly the same as a TEXTEQU.
Why have 2 different reserved words?

It's for compatibility reasons. There was a major overhaul of masm when version changed to 6. They introduced the TEXTEQU directive, but didn't dare to modify the EQU behavior.
Dummheit, gepaart mit Dreistigkeit - eine furchtbare Macht.

hutch--

Something that needs to be understood, when you write an equate, it only exists at assembly time.

In the final binary, an instruction like,

  MyEquate equ <1234>
................
  mov eax, MyEquate   ; in source code
  ; becomes nothing more than
  mov eax, 1234

jj2007

One odd observation is that the order matters. You can redefine equates if the first one was not a number:

include \masm32\include\masm32rt.inc

.code
start:
  cls

  nd equ eax ; equate with or without brackets
  mov eax, 111
  print str$(nd), " is the value of nd", 13, 10

  nd equ 222
  print str$(nd), " is the value of nd", 13, 10

  nd equ <eax>
  mov eax, 333
  print str$(nd), " is the value of nd", 13, 10

  nd equ 444
  print str$(nd), " is the value of nd", 13, 10

  inkey
  exit

end start

StillLearningMasm

Thanks again for the info.

I have another question:
The following is a small program to examine the difference between a EQU text macro string and a string:

cseg segment

start:
.386

qa equ <"2">
qb equ "2"

qaa dw ?
qbb dw ?

mov ax,qa
mov qaa,ax
mov ax,qb
mov qbb,ax

cseg ends
end start

when run:
qa is a string text macro. Value is "2"
qb is a string.                 Value is  0032

Is qa = qb? Is there a difference between a text macro and a string?
Masm seems to assemble them the same way.

if ga and qb are later modified by these instruction:
qa = 1
qb = 1
then these error occur:
qa = 1 ;error A2008: syntax error: integer
qb = 1 ;;error A2005: symbol redefinition: qb

Why do i not get a symbol redefinition error for both of them?