【发布时间】:2015-02-18 18:07:41
【问题描述】:
关于我想要理解的一段代码,我有几个问题。我读过the manual here。但它似乎并没有解释或回答这里使用的所有技巧。
代码如下:
#define SAMPLE_OFFSET1 0
#define SAMPLE_OFFSET2 100
#define SAMPLE_OFFSET1 1000
#define STRINGIFY(s) #s
struct data {
int m1;
int m2;
const uint *m3;
const uint *m4;
};
#define assembly_function(param1, ... param15) \
... body \
... body \
... body \
... body
void testFunction (data* c, uint *const sample) {
int bat, tmp;
__asm__ volatile(
assembly_function("%0", "%q0", "(%4)", "%1", "%w1",
"%2", "%q2", "%3", "%b3",
"%c6(%5)", "%c7(%5)",
STRINGIFY(SAMPLE_OFFSET1),
STRINGIFY(SAMPLE_OFFSET2),
STRINGIFY(SAMPLE_OFFSET3),
"%8")
: "=&r"(bat), "=&r"(c->m1), "=&r"(c->m2), "=&q"(tmp)
: "r"(sample), "r"(c),
"i"(offsetof(data, m3)),
"i"(offsetof(data, m4)),
"1"(c->m1), "2"(c->m2)
: "%rcx", "memory"
);
}
我对以下一些约束/选项的用法有很大的猜测。但我觉得最好从其他人那里确认(或获取一些详细手册的链接)。
- “%c6(%5)”和“%c7(%5)”中的%c
- “%q0”和“%q2”中的%q,
- “%b3”中的%b
- %w in "%w1"
- “(%4)”中的括号
- “i”表示两个输入参数。
- “1”和“2”表示两个输入参数。
感谢您的帮助。
【问题讨论】:
-
远离诡计。坚持简单明了。无论如何,事情都会变得很棘手。