Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

assembly - Gas altmacro macro with a percent sign in a default parameter fails with "% operator needs absolute expression"

I want to create a macro like the following:

.altmacro

.macro assert_eq a, b=%eax
    LOCAL ok
    #...
.endm

To be used as:

assert_eq $1
assert_eq $1, %eax

I want .altmacro for LOCAL (I see the other possibility of using @, but I want LOCAL).

But when I try to compile this I get:

Error: % operator needs absolute expression

I am guessing that this problem is created by the fact that b=%eax is attempting to use another feature enabled by .altmacro: Expression results as strings, since without .altmacro I could write this without problem.

If this is true, how do I escape that for my macro to work? If not, what is wrong with my code?

Bonus question: how to use %?

GAS version: 2.23.52

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I have run into a very similar problem where I wanted to pass registers as arguments to a macro that required the use .altmacro. The fix that worked was to enclose the registers in <> and place ! before %. So try changing your macro to be

.macro assert_eq a, b=<%eax>

and if you ever want to call your macro with a register as an argument do

assert_eq <%eax>, <%ecx>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

63 comments

56.7k users

...