我有下面的内嵌汇编代码。 我得到一个编译错误“错误:无效'asm':在%-letter之后缺少操作数号”%%hi,%lo存在。
void func() { __asm__ ( "lis %%r4, %hi(%0);" "ori %%r4,%%r4,%lo(%0);" "stw r3, 0(%%r4);" "lis %%r4, %hi(%0);" "ori %%r4,%%r4,%lo(%0);" "lis %%r3, %hi(%1);" "ori %%r3,%%r3,%lo(%1);" "stw %%r3, 0(%%r4);" ::"r"(var1), "r"(var2)); }在进一步分析中,我发现只要找到%符号,内联汇编就需要一个数字(%0,%1 ......)。 因此将所有%更改为%%(它只是一个盲目的镜头),然后最终得到许多像下面显示的那样。
{standard input}: Assembler messages: {standard input}:3394: Error: bad expression {standard input}:3394: Error: syntax error; found `h', expected `,' {standard input}:3394: Error: junk at end of line: `hi(%r9)' {standard input}:3394: Error: bad expression {standard input}:3394: Error: syntax error; found `l', expected `,' {standard input}:3394: Error: junk at end of line: `lo(%r9)' {standard input}:3394: Error: bad expression经过大量的努力,我发现如果我们在内联汇编代码中使用%hi()或%lo会有一些问题。 如果我从我的代码中删除%hi和%lo,它就会被编译。 任何人都可以建议我如何在内联汇编代码中使用%hi()和%lo?
I have below in-line assembly code. I am getting a compilation error "error: invalid 'asm': operand number missing after %-letter" at each line where %hi, %lo present.
void func() { __asm__ ( "lis %%r4, %hi(%0);" "ori %%r4,%%r4,%lo(%0);" "stw r3, 0(%%r4);" "lis %%r4, %hi(%0);" "ori %%r4,%%r4,%lo(%0);" "lis %%r3, %hi(%1);" "ori %%r3,%%r3,%lo(%1);" "stw %%r3, 0(%%r4);" ::"r"(var1), "r"(var2)); }On further analysis i found that inline assembly expects a number(%0, %1...) whenever it finds a % symbol. So changed all % to %%(its just a blind shot), then ended up in getting many like the one shown below.
{standard input}: Assembler messages: {standard input}:3394: Error: bad expression {standard input}:3394: Error: syntax error; found `h', expected `,' {standard input}:3394: Error: junk at end of line: `hi(%r9)' {standard input}:3394: Error: bad expression {standard input}:3394: Error: syntax error; found `l', expected `,' {standard input}:3394: Error: junk at end of line: `lo(%r9)' {standard input}:3394: Error: bad expressionafter a lot of efforts i came to know that there is some problem if we use %hi() or %lo in inline assembly code. If i remove %hi and %lo from my code its getting compiled. Can anyone suggest me how to use %hi() and %lo inside a inline assembly code?
最满意答案
GNU AS不支持%hi()和%lo() 。 相反,它在符号上使用@h和@h后缀来表示高低部分。 另请注意,您不能将其与寄存器操作数一起使用,并且您使用了r约束。
GNU AS does not support %hi() and %lo(). Instead, it uses @h and @l suffixes on the symbols to denote the high and low parts. Also note you can't use that with register operands, and you used r constraint.
更多推荐
发布评论