实时动态在内存中编译汇编代码,并返回函数调用指针,可用于JIT系统的后端:
项目地址:http://code.google.com/p/asmpure/
例子:
const char *AlphaBlendAsm = "PROC C1:DWORD, C2:DWORD, A:DWORD\n" " movd mm0, A\n" " punpcklwd mm0, mm0\n" " punpckldq mm0, mm0\n" " pcmpeqb mm7, mm7\n" " psubw mm7, mm0\n" " \n" " punpcklbw mm1, C1\n" " psrlw mm1, 8\n" " punpcklbw mm2, C2\n" " psrlw mm2, 8\n" " \n" " pmullw mm1, mm7\n" " pmullw mm2, mm0\n" " paddw mm1, mm2\n" " \n" " psrlw mm1, 8\n" " packuswb mm1, mm1\n" " movd eax, mm1\n" " emms\n" " ret\n" "ENDP\n"; void testAlphaBlend(void) { CAssembler *casm; int c; int (*AlphaBlendPtr)(int, int, int); // create assembler casm = casm_create(); // append assembly source casm_source(casm, AlphaBlendAsm); AlphaBlendPtr = (int (*)(int, int, int))casm_callable(casm, NULL); if (AlphaBlendPtr == NULL) { printf("error: %s\n", casm->error); casm_release(casm); return; } printf("==================== Alpha Blend ====================\n"); casm_dumpinst(casm, stdout); printf("\nExecute code (y/n)?\n\n"); do { c = getch(); } while(c != 'y' && c != 'n'); if(c == 'y') { int x = AlphaBlendPtr(0x00FF00FF, 0xFF00FF00, 128); printf("output: %.8X\n\n", x); } free(AlphaBlendPtr); casm_release(casm); }
output: 7f7f7f7f
大侠, 看了你几个开源项目, 感觉您写的代码好高深, 您有多少年开发经验,对于新手如何提升自己开发能力,您能指点一二吗. 实在佩服您的水平.
我写代码十七年了。。。。还是要多写多练呀,才能提高呀。。。。
你好,asmpure不支持masm的“mov ecx,[0x7549B4]”这种语法吗?
有没其他方法作为替代?