pranith
pranith

Reputation: 879

How does this inline assembly define a variable?

In the linux kernel you find assembly as follows:

#define DEFINE(sym, val) \
        asm volatile("\n->" #sym " %0 " #val : : "i" (val))

which when used like this

DEFINE(NR_PAGEFLAGS, __NR_PAGEFLAGS);

generates the following assembly

->NR_PAGEFLAGS $24 __NR_PAGEFLAGS

which apparently is valid assembly. What does this do?

How does this asm define a variable? Please point me to any documentation which explains this in more detail. Thanks!

Upvotes: 1

Views: 539

Answers (1)

Timothy Baldwin
Timothy Baldwin

Reputation: 3675

This is not valid assembly. It gets transformed using a sed script into something like:

#define NR_PAGEFLAGS 24

This file is then included by many assembly source files, this allows the results of C constant expressions used in assembler files.

Upvotes: 5

Related Questions