Do you want TEST or CMP . TEST is the easiest in this case:
XOR EAX,EAX MOV AL,isPatched //isPatched would be a byte, hence we need correct operand sizes TEST EAX,EAX JE NotSet Set: //handle true case JMP End NotSet: //handle false case End: //continue
Depending on other cases, you can also use SUB , SETcc or MOVcc
Your problem is one of the scope, isPatched not the scope when using ASM, so it is assumed that it is a DWORD , and then cannot find the memory label (symbol name) for it when generating addresses. You also need to use the correct operand size for bool .
Dirty litte test for MSVC
bool b = true; int __declspec( naked ) test(void) { __asm { xor eax,eax MOV al, b TEST eax,eax JE NotSet mov eax,1 NotSet: RETN } } int _tmain(int argc, _TCHAR* argv[]) { printf("%d\n", test()); system("pause"); return 0; }
this pin is 1 when b is true , or 0 when b is false .
source share