@instruction<EOL><INDENT>def CMPXCHG8B(cpu, dest):<DEDENT>
size = dest.size<EOL>cmp_reg_name_l = {<NUM_LIT:64>: '<STR_LIT>', <NUM_LIT>: '<STR_LIT>'}[size]<EOL>cmp_reg_name_h = {<NUM_LIT:64>: '<STR_LIT>', <NUM_LIT>: '<STR_LIT>'}[size]<EOL>src_reg_name_l = {<NUM_LIT:64>: '<STR_LIT>', <NUM_LIT>: '<STR_LIT>'}[size]<EOL>src_reg_name_h = {<NUM_LIT:64>: '<STR_LIT>', <NUM_LIT>: '<STR_LIT>'}[size]<EOL>cmph = cpu.read_register(cmp_reg_name_h)<EOL>cmpl = cpu.read_register(cmp_reg_name_l)<EOL>srch = cpu.read_register(src_reg_name_h)<EOL>srcl = cpu.read_register(src_reg_name_l)<EOL>cmp0 = Operators.CONCAT(size, cmph, cmpl)<EOL>src0 = Operators.CONCAT(size, srch, srcl)<EOL>arg_dest = dest.read()<EOL>cpu.ZF = arg_dest == cmp0<EOL>dest.write(<EOL>Operators.ITEBV(size, cpu.ZF,<EOL>Operators.CONCAT(size, srch, srcl),<EOL>arg_dest)<EOL>)<EOL>cpu.write_register(cmp_reg_name_l, Operators.ITEBV(size // <NUM_LIT:2>, cpu.ZF, cmpl,<EOL>Operators.EXTRACT(arg_dest, <NUM_LIT:0>, size // <NUM_LIT:2>)))<EOL>cpu.write_register(cmp_reg_name_h, Operators.ITEBV(size // <NUM_LIT:2>, cpu.ZF, cmph,<EOL>Operators.EXTRACT(arg_dest, size // <NUM_LIT:2>, size // <NUM_LIT:2>)))<EOL>
Compares and exchanges bytes.

Compares the 64-bit value in EDX:EAX (or 128-bit value in RDX:RAX if
operand size is 128 bits) with the operand (destination operand). If
the values are equal, the 64-bit value in ECX:EBX (or 128-bit value in
RCX:RBX) is stored in the destination operand.  Otherwise, the value in
the destination operand is loaded into EDX:EAX (or RDX:RAX)::

        IF (64-Bit Mode and OperandSize = 64)
        THEN
            IF (RDX:RAX = DEST)
            THEN
                ZF = 1;
                DEST = RCX:RBX;
            ELSE
                ZF = 0;
                RDX:RAX = DEST;
            FI
        ELSE
            IF (EDX:EAX = DEST)
            THEN
                ZF = 1;
                DEST = ECX:EBX;
            ELSE
                ZF = 0;
                EDX:EAX = DEST;
            FI;
        FI;

:param cpu: current CPU.
:param dest: destination operand.