elflyao
elflyao

Reputation: 387

How to do arbitary text replacement in gnu assembler

a:.int 0
movl $0,a(%rip)

Is there a way to do something like #define b a(%rip) such that every instance of b will be replaced by a(%rip), so that movl $0,a(%rip) could be abbreviated as movl $0,b? I've tried both b=a(%rip) and .macro b;a(%rip);.endm but neither worked. Any help will be appreciated.

Upvotes: 1

Views: 262

Answers (1)

fuz
fuz

Reputation: 92994

You can preprocess your file with the C preprocessor and then indeed use #define b a(%rip). To have the file preprocessed with the C preprocessor, use the file suffix .S instead of .s and assemble like this:

cc -c file.S

Note that a definition like this is very unusual and confusing to readers. Instead of trying to change assembler syntax that is confusing to you by the mean of macros, I recommend you to get familiar with the syntax and the reasons why you use a %rip-relative addressing mode instead.

Upvotes: 2

Related Questions