周航慈的书上有这么一段话“某条指令前如果插入2条nop指令,则这条指令就不会被前面冲下来的失控程序拆散,并将被完整执行。”
#include <intrins.h>
unsigned char xdata add0 _at_ 0;
unsigned char xdata add1 _at_ 1;
//Sum函数对应的机器码。假设程序飞到操作数02 将其当做操作码。运行后发现2个_nop_之后的指令没有执行,直接飞到地址0x00去了。
unsigned char code SUM_TEST[] = {
0Xed, 0x2f, 0xff, 0xe4, 0x33, 0xfe, /*0x90, 0x00,*/ 0x02, _nop_, _nop_,
0xf0, 0xa3, 0xef, 0xf0, 0x22
};
unsigned short Sum(unsigned char a, unsigned char b)
{
unsigned short xdata value;
value = a + b;
return value;
}
void main(void)
{
unsigned short (*pFun)(unsigned char a, unsigned char b);
unsigned short value;
Sum(7, 9);
pFun = SUM_TEST;
value = pFun(7, 10);
_nop_();
while (1)
{
}
} |