/ tst_and_clr.s / EMACS_MODES: !c !fill / This C-callable routine performs an atomic test-and-clear operation / on a single character variable whose address is passed it as parameter / pvar. It clears the variable and returns 1 if its original value / was 1, 0 otherwise. It uses the rorb instruction to guarantee atomicity. / / Calling sequence: / tst_and_clr (pvar) / char *pvar; / Returns: / R0 == 0 if *pvar was 0 / R0 == 1 if *pvar was 1 / Destroys R1 / .globl _tst_and_clr pvar = 2 / ptr. to var to be tested _tst_and_clr: mov pvar(sp),r1 / point to var clr r0 / assume 0 return (note that this also / clears the carry bit, for the rotate) rorb (r1) / do it jcc 1f / if var was 0, branch inc r0 / it was 1, return 1 1: rts pc