_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:
produces the following machine-code when i read from void program function-pointer:
so far so good, it produces: 02 c0 //add al, al
Here are some example with it:
produces the following machine-code:
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())
any ideas?
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?
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?
so more specifically the question is, is there a way to turn off this push and pop opcodes/instructions in the compiler-options?
ok, i found out the cause. the compiler generated prolog and epilog code. i simply turned it off with __declspec(naked) int Program() { ... } :P
Quote:
__declspec(naked) int Program() { ... } :P
naked programming :D