如何使用C中的位(硬码)内联汇编代码?
我们可以使用__ ASM __()
使用内联装配。但是,这种方法只能支持编译器识别的指令。
我正在使用的是Gem5硬件模拟器,其中我在RISCV中实现了新的指令。这样的指令是1和0的弦。因此,如果此类指令在可执行文件中,则将由GEM5硬件模拟器获取,解码和执行。
但是,由于这是一项新指令,因此编译器无法识别它。
例如,假设我实施的指令具有助记符newinst%A0,%A1
。如果我直接使用
__asm__("newInst %0, %1": /* etc... */);
编译器的内联装配插入它,将无法将其转换为机器代码。
因此,我可以知道是否有一种方法可以使用内联装配中的指令进行硬编码,而无需修改编译器?
We can use inline assembly by using __asm__()
. However, this approach can only support instructions that are recognized by the compiler.
What I am using is gem5 hardware simulator, in which I implemented a new instruction in RISCV. Such instruction is a bit string of 1's and 0's. Hence, if such instruction is in the executable, then it will be fetched, decoded and executed by gem5 hardware simulator.
However, since that is a new instruction, the compiler does not recognize it.
For example, suppose the instruction that I implemented has mnemonic newInst %a0, %a1
. If I directly insert it using inline assembly by
__asm__("newInst %0, %1": /* etc... */);
The compiler would not be able to translate that into machine code.
Hence, may I know if there is a way to hard code the instruction using inline assembly, without modifying the compiler?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
.byte
a>:You can put raw bytes in with
.byte
: