pouët.net

_emit pseudoinstruction (inline asm, visual c++)

category: code [glöplog]
 
Did some research and found the _emit instruction for inline assembly in Visual C++ that basically does the same thing as db 0x... or .byte 0x.. in assembly language. But I found that there is a problem, it includes some prefix and postfix bytes I want to get rid of them, but is it possible? I want to do some tests and need the address or function pointer to be at the exact start of the inline assembly instructions and machinecode.

Here are example without the _emit:
Code:_asm add al, al

produces the following machine-code when i read from void program function-pointer:
Quote:
02 c0 c3

so far so good, it produces: 02 c0 //add al, al

Here are some example with it:
Code:_asm { add al, al _emit 0x34 _emit 0x35 _emit 0x36 _emit 0x37 }


produces the following machine-code:
Quote:
53 56 57 02 c0 34 35 36 37 5f 5e 5b c3

here the 52 56 57 prefix bytes are included, and the 5f e5 5b postfix bytes what does these mean? where can i find documentation if and how _emit does this? I tried several code and linker options without luck.

The original-program looks like this (i tried to remove some junk): (I read address from Program() and Entrypoint())
Code: void Program() { _asm add al, al //_asm _emit ....etc... } void Entrypoint() { BYTE a, *b; void(*memaddr)() = &Entrypoint; void(*pf)() = &Program; char *ptr = (char*)pf; printf("Program = %i\n", &pf); printf("Entrypoint = %i\n", &memaddr); int ProgramLen = (int)memaddr - (int)pf; for (int i=0; i<ProgramLen; i++) printf("%02x ", (BYTE)ptr[i]); printf("\n"); system("pause"); }


any ideas?
added on the 2016-09-09 01:31:44 by rudi rudi
sorry for not doing the proper research, those prefix and postfix bytes are: push and pop eBX, eSI and eDI registers, but that still doesnt solve the fact that these are implemented by the compiler.

so more specifically the question is, is there a way to turn off this push and pop opcodes/instructions in the compiler-options?
added on the 2016-09-09 01:43:18 by rudi rudi
ok, i found out the cause. the compiler generated prolog and epilog code. i simply turned it off with __declspec(naked) int Program() { ... } :P
added on the 2016-09-09 01:58:39 by rudi rudi
Quote:
__declspec(naked) int Program() { ... } :P

naked programming :D
added on the 2016-09-09 14:19:47 by lollol lollol

login