English
Language : 

MC68030 Datasheet, PDF (104/602 Pages) Motorola, Inc – ENHANCED 32-BIT MICROPROCESSOR
Instruction Set Summary
The CAS and CAS2 instructions together allow safe operations in the manipulation of
system linked lists. Controlling a single location, HEAD in the example, manages a last-in-
first-out linked list (see Figure 3–2). If the list is empty, HEAD contains the NULL pointer (0);
otherwise, HEAD contains the address of the element most recently added to the list. The
code fragment shown in Figure 3–2 illustrates the code for inserting an element. The MOVE
instructions load the address in location HEAD into D0 and into the NEXT pointer in the
element being inserted, and the address of the new element into D1. The CAS instruction
stores the address of the inserted element into location HEAD if the address in HEAD
remains unaltered. If HEAD contains a new address, the instruction loads the new address
into D0 and branches to the second MOVE instruction to try again.
The CAS2 instruction is similar to the CAS instruction except that it performs two
comparisons and updates two variables when the results of the comparisons are equal. If
the results of both comparisons are equal, CAS2 copies new values into the destination
addresses. If the result of either comparison is not equal, the instruction copies the values
in the destination addresses into the compare operands.
SINSERT
SILOOP
MOVE.L
MOVE.L
MOVE.L
CAS.L
BNE
HEAD.D0
D0, (NEXT, A1)
A1, D1
D0, D1, HEAD
SILOOP
ALLOCATE NEW ENTRY, ADDRESS IN A1
MOVE HEAD POINTER VALUE TO D0
ESTABLISH FORWARD LINK IN NEW ENTRY
MOVE NEW ENTRY POINTER VALUE TO D1
IF WE STILL POINT TO TOP OF STACK, UPDATE THE HEAD POINTER
IF NOT, TRY AGAIN
BEFORE INSERTING AN ELEMENT:
ENTRY
+ NEXT
NEW
?
HEAD
ENTRY
+ NEXT
ENTRY
+ NEXT
AFTER INSERTING AN ELEMENT:
ENTRY
ENTRY
HEAD
NEW
+ NEXT
+ NEXT
Figure 3-2. Linked List Insertion
ENTRY
+ NEXT
3-26
MC68030 USER’S MANUAL
MOTOROLA