스핀락을 구현하기 위해 x86 어셈블리어를 사용한 예이다. 인텔80386 호환 프로세서라면 동작한다.
; Intel syntaxlocked:; The lock variable. 1 = locked, 0 = unlocked.dd0spin_lock:moveax,1; Set the EAX register to 1.xchgeax,[locked]; Atomically swap the EAX register with; the lock variable.; This will always store 1 to the lock, leaving; the previous value in the EAX register.testeax,eax; Test EAX with itself. Among other things, this will; set the processor's Zero Flag if EAX is 0.; If EAX is 0, then the lock was unlocked and; we just locked it.; Otherwise, EAX is 1 and we didn't acquire the lock.jnzspin_lock; Jump back to the MOV instruction if the Zero Flag is; not set; the lock was previously locked, and so; we need to spin until it becomes unlocked.ret; The lock has been acquired, return to the calling; function.spin_unlock:moveax,0; Set the EAX register to 0.xchgeax,[locked]; Atomically swap the EAX register with; the lock variable.ret; The lock has been released.