What is the difference? It looks like they do the same thing.
I'm not so sure I like Don's way of saying it, though it may be
correct, in part. Since you don't say which system you are working
on, I'll just assume you mean a comparison of a c-style #define and an
assembler style of EQU, when I speak, since that seems more likely to
me. (Sometimes, assemblers will actually support a c-style #define,
too, though I cannot think of a c-compiler that supports an assembler
style EQU.) Also, there is an aspect of #define that does support
parameters, but I'll assume that you are really just talking about
comparing:
#define MYSYM 10
and,
MYSYM EQU 10
rather than,
#define MYSYM(a) 10*(a)
and,
MYSYM EQU 10*(a)
which is a different comparison.
In an assembler like MASM for the PC, which supports an EQU, the EQU
actually creates a symbol (or may, anyway) and an associated value
that is placed into the object file that the linker can examine,
later. THis means that the symbol can be referenced in other source
code files.
In c (and probably any assembler also supporting it), the #define only
creates that symbol in the compiler's temporary internal memory for
the duration of the compilation. In that case, the symbol does NOT
then appear in the object file, at all. It's kind of like entering a
search-and-replace in your editor, that replaces all cases of the
symbol in your text to the indicated value before compilation. The
compiler never even "sees" the symbol. It's just not there, when the
c compiler gets around to parsing the code.
For example,
--- assembler source file #1 ---
SIZE EQU 10
PUBLIC SIZE
D DW SIZE DUP( 1 )
--- end ---
--- assembler source file #2 ---
EXTERN SIZE:ABS
mov cx, SIZE
--- end ---
If you assemble #1, it will not only use the value of SIZE in creating
the list of 10 constant-one's for the D-array, but it will also place
a symbol called SIZE into its object file for use by the linker. When
the assembler assembles #2, it places a reference in its object file
to link up with the value of SIZE to move into the CX register. When
the linker gets around to pasting these two files together, it finds
the value defined in #1 and replaces the reference to it in #2 with
the correct value and then completes the link up, which means that the
value 10 will be correctly placed into CX when the program runs.
In c, there is no equivalent to EQU.
However, in x86 assembler, there is an equivalent to #define. It's
simply the = sign. For example,
MYSYM = 10
In this case, the value in MYSYM only exists for the duration of the
assembly processes and the symbol MYSYM will not be placed into the
object file.
It's one of the many examples where the available semantics to the
assembly writer exceeds the semantics available to the c programmer.
Jon