本文介绍了在GCC中实现Borland的__emit__宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Borland中,有一个宏 __ emit __ ,一个将文字值直接注入目标代码的伪函数()。

gcc / g ++是否有等价物?
(我似乎无法在文档中找到它)



如果不是,我该如何在C ++源代码中实现它?






用法可以在

解决方案

您可以看看汇编指令:

  asm __volatile__(.byte 0xEA,0x00,0x00,0xFF,0xFF); 

GCC的优化器有时会放弃 asm 语句确定不需要输出变量。另外,如果优化器相信代码总是返回相同的结果(即,它的输入值在调用之间没有任何变化),则优化器可以将代码移出循环。 。



无论如何,您应该注意许多角落案例(例如 gcc在跳转后跳过asm代码 a> ...)


In Borland, there is a macro __emit__, "a pseudo-function that injects literal values directly into the object code" (James Holderness).

Is there an equivalent for gcc / g++?(I can't seem to find one in the documentation)

If not, how could I implement it in my C++ source code?


Usage can be found at Metamorphic Code Examples

解决方案

You can take a look at .byte assembler directive:

asm __volatile__ (".byte 0xEA, 0x00, 0x00, 0xFF, 0xFF");

GCC's optimizers sometimes discard asm statements if they determine there is no need for the output variables. Also, the optimizers may move code out of loops if they believe that the code will always return the same result (i.e. none of its input values change between calls). Using the volatile qualifier disables these optimizations.

Anyway you should pay attention to many corner cases (e.g. gcc skips asm code after goto...)

这篇关于在GCC中实现Borland的__emit__宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 15:01