.Code% MVN R0, #0 \ Set new state of flag - no access allowed. ADR R2, Flag% \ Get address of flag. .Loop% SWP R1, R0, [R2] \ Swap old and new states of flag. TEQS R1, #0 \ Is access allowed? BNE Loop% \ If not, keep waiting. .DoSomething% \ \ ... Do something ... .Exit% MOV R0, #0 \ Set new state of flag - access allowed. ADR R2, Flag% \ Get address of flag. STR R0, [R2] \ Store new state of flag. MOV R15, R14 \ Return to caller. .Flag% EQUD 0 \ Reserve memory for flag.