public static unsafe uint CompareExchange(uint *location, uint value, uint comparand) { Asm.MOV(R32.ECX, location); Asm.MOV(R32.EDX, &value); Asm.MOV(R32.EAX, &comparand); Asm.LOCK(); Asm.CMPXCHG(R32.ECX, R32.EDX); Asm.MOV(location, R32.EAX); return(*location); }