EasyManuals Logo

Motorola MC68030 User Manual

Motorola MC68030
254 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #103 background imageLoading...
Page #103 background image
Instruction Set Summary
MOTOROLA MC68030 USER’S MANUAL 3-25
3.5 INSTRUCTION EXAMPLES
The following paragraphs provide examples of how to use selected instructions.
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
multitasking 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 accessing 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 D0 and stores the new
count value in register D1. 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 portion of the
cycle copies the new count in SYS_CNTR into D0, and the routine branches to repeat the
test. The following code sequence guarantees that SYS_CNTR is correctly incremented.
MOVE.W SYS_CNTR,D0 get the old value of the counter
INC_LOOP MOVE.W D0,D1 make a copy of it
ADDQ.W #1,D1 and increment it
CAS.W D0,D1,SYS_CNTR if countr value is still the same, update it
BNE INC_LOOP if not, try again

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Motorola MC68030 and is the answer not in the manual?

Motorola MC68030 Specifications

General IconGeneral
BrandMotorola
ModelMC68030
CategoryComputer Hardware
LanguageEnglish

Related product manuals