带有内联汇编代码的%hi()和%lo()的编译错误(Compilation error with %hi() and %lo() with inline assembly code)

编程入门 行业动态 更新时间:2024-10-18 06:00:19
带有内联汇编代码的%hi()和%lo()的编译错误(Compilation error with %hi() and %lo() with inline assembly code)

我有下面的内嵌汇编代码。 我得到一个编译错误“错误:无效'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 expression

after 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.

更多推荐

本文发布于:2023-07-25 05:42:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1256797.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:内联   错误   代码   lo   Compilation

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!