Reputation: 341
To handle concurrency in an M68000 assembly program, I need to understand how the TAS instruction works.
I don't really care about the theoretical description that I can see from the manual (e.g. http://68k.hax.com/TAS). More than anything I would like to see some examples.
Upvotes: 0
Views: 1024
Reputation: 6063
Actually, there isn't much to this instruction. A typical piece of spin lock code in 68k assembly could look like that:
lea.l spinLock(pc),a0
getLock:
tas (a0)
bne.s getLock
bra haveLock
spinLock
dc.b 0
The code sets the MSB of the byte at spinLock
, and loops around until the zero flag is set (telling you the bit was not set before, i.e. no other piece of code has already acqiured the lock). The important thing is the TAS instruction is atomic, that is, it cannot be interrupted by other code (like an ISR, for example) between the bit test and the set.
Upvotes: 3