Reply to thread

Attempting a new method.


[code][NO-PARSE]#include <iostream>

#include <cstdint>


uint32_t f_parity(uint32_t v)

{

    uint32_t p = 0;

    __asm

    {

        mov eax, v   // move value to eax register

        or eax, eax  // logical or on eax register with saved result (eax |= eax)

        pushfd       // push EFLAGS register contents to stack

        pop eax      // grab EFLAGS register value from stack

        shr eax, 2   // shift right twice

        and eax, 1   // grab the PF bit

        mov p, eax   // move eax register to variable p

        xor eax, eax // clear eax register

    }

    return p;

}


int main_method(void)

{

    uint32_t n = 23784;

    std::cout << f_parity(n);

    std::endl(std::cout);

    return 0;

}[/NO-PARSE][/code]


Taken from the EFLAGS register by using the pushfd instruction. Keep note that registers are 32 bits though. They can be split up, but this method will only work for 32 bit.


Back
Top