Random Guy
Random Guy

Reputation: 1134

EQU directive in GAS assembly

Why does .equ directive not work in gas in this way:

.equ Mark64, 8(%rsi)

while it works in this (note: .text section, where Mark32 is located, is set to r/w in this case):

Mark32 EQU DWORD PTR [ESI + 4]

How can i make Mark64 work in GAS (.set also doesn't work)?

Thanks in advance!

Upvotes: 2

Views: 4448

Answers (2)

Peter Cordes
Peter Cordes

Reputation: 364288

In some assembly languages (e.g. MASM) equ is a text substitution.

But in GAS, .equ is a numeric constant, like foo = 3 in MASM. For text substitutions, use the C preprocessor #define Mark64 8(%rsi). Name your file foo.S so gcc will run it through CPP before assembling.

equ in NASM also defines a numeric assemble-time constant, and uses %define for text substitutions.


And BTW, defining Mark64 to 8(%rsi) seems like a bad / confusing idea. People don't expect something that looks like a symbol name to actually contain a register reference. Defining the numeric magic constant 8 to a meaningful name could be good, though.

Upvotes: 2

Random Guy
Random Guy

Reputation: 1134

Data section:

MarksTable:
    .quad Mark64_1
    .quad Mark64_2
    .quad Mark64_3

where Mark64_x is just a label in code section.

And then I've just placed my MarksTable into reg:

movq MarksTable, %rsi

After all I could access Mark64_2 for instance from rsi like this:

callq   *0x8(%rsi)

Upvotes: -1

Related Questions