Motorola MC68030 User Manual page 104

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

Advertisement

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
MOVE.L
SILOOP
MOVE.L
MOVE.L
CAS.L
BNE
BEFORE INSERTING AN ELEMENT:
NEW
AFTER INSERTING AN ELEMENT:
HEAD
NEW
3-26
ALLOCATE NEW ENTRY, ADDRESS IN A1
HEAD.D0
MOVE HEAD POINTER VALUE TO D0
D0, (NEXT, A1)
ESTABLISH FORWARD LINK IN NEW ENTRY
A1, D1
MOVE NEW ENTRY POINTER VALUE TO D1
D0, D1, HEAD
IF WE STILL POINT TO TOP OF STACK, UPDATE THE HEAD POINTER
SILOOP
IF NOT, TRY AGAIN
ENTRY
+ NEXT
?
HEAD
ENTRY
+ NEXT
Figure 3-2. Linked List Insertion
MC68030 USER'S MANUAL
ENTRY
+ NEXT
ENTRY
+ NEXT
ENTRY
+ NEXT
ENTRY
+ NEXT
MOTOROLA

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents