وو

وحید آنلاین . آرشیو وبلاگ وحیدمی دات آی آر . شرکت بیان. vahidmy.blog.ir

وو

وحید آنلاین . آرشیو وبلاگ وحیدمی دات آی آر . شرکت بیان. vahidmy.blog.ir

MWAIT

MWAIT 

Usage:  MWAIT  eax,ecx                                      Modifies flags: None.

A hint that allows the processor to stop instruction execution and enter an implementation-dependent optimized state until occurrence of a class of events; it is architecturally identical to a NOP instruction.

Monitor Wait


MWAIT eax,ecx                   ; 0F 01 C9         [Pent4]


The MWAIT instruction is designed to operate with the MONITOR instruction. The two instructions allow the definition of an address at which to 'wait' (MONITOR). The execution of MWAIT is a hint to the  processor that it can enter an implementation - dependent - optimized state while waiting for an event or a store operation to the address range armed by the preceding MONITOR instruction in program flow.


EXAMPLE:

L1: mov EAX  TriggerAddress

mov ECX 0 ;Hints 

mov EDX 0 ; Hints 

If Trigger_store_happened 

MONITOR 

If Trigger_store_happened  

MWAIT | jmp L1


The MONITOR and MWAIT instructions must be coded in the same loop because execution of the MWAIT  instruction will trigger the monitor hardware. It is not a proper usage to execute MONITOR once and then execute MWAIT in a loop. 


Setting up MONITOR without executing MWAIT has no adverse effects. Typically the MONITOR/MWAIT pair is used in a sequence.


The above code sequence makes sure that a triggering store does not happen between the first check of the trigger and the execution of the monitor instruction. Without the second check that triggering store would go un-noticed.