处理器寄存器-应用程序变量关联
我有一个非常简单的问题。我想编写一些直接在单个寄存器(称为 %o1)上运行的汇编代码(用于 SPARC)。我想做的就是用零初始化这个寄存器,然后用一些立即值递增它。问题是,如何从 C 应用程序输出 %o1 中的结果。我的骨架看起来像这样:
void main()
{
int a;
asm volatile (
".text\n\t"
"mov 0, %o1 \n\t"
"add %o1, 1, %o1 \n\t"
"add %o1, 2, %o1 \n\t"
"add %o1, 3, %o1 \n\t"
);
// assign content of register %o1 somehow to variable a (a = %o1);
printf("%i\n", a);
}
所以问题是如何分配 %o1 的值(到结束时应该是 6) 计算)到变量a,以便它可以打印在控制台上。
I have a very simple problem. I wanna write some assembler code (for SPARC) that directly operates on a single register, called %o1. All I wanna do is to initialise this register with zero, and then increment it with some immediate values. The problem is, how can I output the result in %o1 from a C-application. The skeleton I have looks like that:
void main()
{
int a;
asm volatile (
".text\n\t"
"mov 0, %o1 \n\t"
"add %o1, 1, %o1 \n\t"
"add %o1, 2, %o1 \n\t"
"add %o1, 3, %o1 \n\t"
);
// assign content of register %o1 somehow to variable a (a = %o1);
printf("%i\n", a);
}
So the question is how do I assign the value of %o1 (which should be 6 by the end of
the calculation) to variable a so that it can be printed on the console.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它依赖于编译器。对于 gcc: http://gcc.gnu.org/onlinedocs/gcc/Extended- Asm.html
更新: 看起来 gcc 不允许在 SPARC 上选择特定寄存器。
还有另一个扩展: http://gcc.gnu.org/ onlinedocs/gcc/Local-Reg-Vars.html
It's compiler dependent. For gcc: http://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html
Update: looks like gcc do not allow selecting specific registers on SPARC.
There is another extension for this: http://gcc.gnu.org/onlinedocs/gcc/Local-Reg-Vars.html
这在很大程度上取决于您的编译器(您没有告诉我们),请查找其文档。对于 gcc 来说,语法类似于
This is much depending on your compiler (which you didn't tell us), look up its documentation. For gcc the syntax would be something like