SPARC 大会问题
我想在我的 C 程序中编写一个非常简单的内联汇编例程,它什么也不做 否则,将本地寄存器 %l0 - %l7 设置为不同的值。我尝试了以下简单的方法:
asm volatile (
".text\n\t"
"mov 0, %%l0 \n\t"
"mov 1, %%l1 \n\t"
"mov 2, %%l2 \n\t"
"mov 3, %%l3 \n\t"
"mov 4, %%l4 \n\t"
"mov 5, %%l5 \n\t"
"mov 6, %%l6 \n\t"
"mov 7, %%l7 \n\t"
);
不幸的是,汇编器告诉:每条指令的操作数都是非法的。有人能好心地告诉我如何正确地将立即值传递给 SPARC 汇编器吗?
非常感谢!
编辑:谢谢克里斯,我做了你建议的更改,但 Sparc 编译器仍然告诉一些有关非法操作数的信息......
I wanna write a very simple inline assembly routine in my C program which does nothing
else then setting the local registers %l0 - %l7 to different values. I tried the following straightforward approach:
asm volatile (
".text\n\t"
"mov 0, %%l0 \n\t"
"mov 1, %%l1 \n\t"
"mov 2, %%l2 \n\t"
"mov 3, %%l3 \n\t"
"mov 4, %%l4 \n\t"
"mov 5, %%l5 \n\t"
"mov 6, %%l6 \n\t"
"mov 7, %%l7 \n\t"
);
unfortuantely, the assembler tells: illegal operand for each instruction. Could somebody please be so nice to point me out how I can properly pass immediate values to the SPARC assembler?
Thanks so much!
EDIT: Thanks Chris, I made the changes you suggested but the Sparc compiler still tells some something about illegal operands...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
SPARC 本身不发出“立即移动”指令;有
或
可以像或 %g0, 123, %l0
一样使用(或者用零寄存器来表示一个不超过 11 位的常量,< code>%g0,导致将所述常量移动到目标寄存器中),或可用于设置 a 的高 21 位的sethi
指令登记。为了适应任何(32位)常量,您必须首先对高位执行sethi
来合成一个两步set
后面跟着一个or
以及较低的那些。SPARC 汇编程序通常知道一个
set ..., %tgtregister
快捷方式来创建此序列,和/或消除一条指令(如果常量适合该指令)。另请注意,在 64 位/sparcv9 中,
set
指令最终可能会计算出最多五个指令的序列,将事物移位/或在一起。SPARC doesn't mave "immediate move" instructions as such; there's either
or
which can be used likeor %g0, 123, %l0
(or'ing a no-more-than 11-bit constant with the zero register,%g0
, resulting in moving said constant into the target register), or thesethi
instruction that can be used to set the upper 21 bits of a register. In order to accommodate any (32bit) constant, you therefore have to synthesise a two-stepset
by doing asethi
first for the upper bits followed by anor
with the lower ones.SPARC assemblers usually know a
set ..., %tgtregister
shortcut to create this sequence, and/or eliminate one instruction should the constant be fit for that.Also note that in 64bit / sparcv9, the
set
instruction may ultimately evaluate to a sequence of up to five instructions, shifting/or'ing things together.您需要像
mov 0, %%l0
-- 源然后目标这样的行,并且常量只是常量,没有“#”字符。编辑
如果您的 asm 指令中没有任何约束(只是一个字符串),则 gcc 不会处理该字符串的 % 转义符。因此,在这种情况下,您只需在寄存器名称前添加一个
%
字符即可。但是,如果您添加任何约束(甚至只是在字符串后添加::
- 一个空约束集),它会查找 %-转义符,因此您需要%%
用于寄存器名称。因此,要么在
)
之前添加::
,要么取消重复的%
字符。You want lines like
mov 0, %%l0
-- source then destination, and constants are just constants, no '#' character.edit
If you have no constraints in your asm directive (just a string), then gcc doesn't process the string for %-escapes. So in that case you need just single
%
characters before the register name. But if you add any constraints (or even just::
after the string -- an empty constraint set), it will look for %-escapes, so you need%%
for register names.So either add a
::
just before the)
or un-duplicate the%
characters.