Instruction Examples; Using The Cas And Cas2 Instructions - Motorola MC68030 User Manual

Enhanced 32-811 microprocessor
Hide thumbs Also See for MC68030:
Table of Contents

Advertisement

3.5 INSTRUCTION EXAMPLES
The following paragraphs provide examples of how to use selected instruc-
tions.
3.5.1 Using the CAS and CAS2 Instructions
The CAS instruction compares the value in a memory location with the value
in a data register, and copies a second data register into the memory location
if the compared values are equal. This provides a means of updating system
counters, history information, and globally shared pointers. The instruction
uses an indivisible read-modify-write cycle; after CAS reads the memory
location, no other instruction can change that location before CAS has written
the new value. This provides security in single-processor systems, in multi-
tasking environments, and in multiprocessor environments. In a single-
processor system, the operation is protected from instructions of an interrupt
routine. In a multitasking environment, no other task can interfere with writing
the new value of a system variable. In a multiprocessor environment, the
other processors must wait until the CAS instruction completes before ac-
cessing a global pointer.
The following code fragment shows a routine to maintain a count, in location
SYS-CNTR, of the executions of an operation that may be performed by any
process or processor in a system. The routine obtains the current value of
the count in register DO and stores the new count value in register 01. The
CAS instruction copies the new count into SYS-CNTR if it is valid. However,
if another user has incremented the counter between the time the count was
stored and the read-modify-write cycle of the CAS instruction, the write por-
tion of the cycle copies the 'new count in SYS-CNTR into ~O, and the routine
branches to repeat the test. The following code sequence guarantees that
SYS-CNTR is correctly incremented.
MOVE.W
INC-LOOP
MOVE.W
MOTOROLA
AOOQ.W
CAS.W
BNE
SYS_CNTR,OO
00,01
#1,01
00,01,SYS-CNTR
INC_LOOP
get the old value of the counter
make a copy of it
and increment it
if counter value is still the same, update it
if not, try again
MC68030 USER'S
MANUAL
3-25

Advertisement

Table of Contents
loading

Table of Contents