Instruction Set Summary
MOTOROLA MC68030 USER’S MANUAL 3-29
When the list contains only one element, the routine branches to the CAS2 instruction at
label DDEMPTY after moving a zero pointer value into D2. This instruction checks the
addresses in LIST_PUT and LIST_GET to verify that no other routine has inserted another
element or deleted the last element. Then the instruction moves zero into both pointers, and
the list is empty.
Figure 3-4. Doubly Linked List Insertion
BEFORE INSERTING NEW ENTRY:
DINSERT
DILOOP
DIEMPTY
DIDONE
LEA LIST_PUT, A0
LEA LIST_GET, A1
MOVE.L A2, D2
MOVE.L (A0), D0
TST.L D0
BEQ DIEMPTY
MOVE.L D0, (NEXT, A2)
CLR.L D1
MOVE.L D1, (LAST, A2)
LEA (LAST, D0), A1
CAS2.L D0:D1,D2:D2,(A0):(A1)
BNE DILOOP
BRA DIDONE
MOVE.L D0, (NEXT, A2)
MOVE.L D0, (LAST, A2)
CAS2.L D0:D0,D2:D2,(A0):(A1)
BNE DILOOP
(ALLOCATE NEW LIST ENTRY, LOAD ADDRESS INTO A2)
LOAD ADDRESS OF HEAD POINTER INTO A0
LOAD ADDRESS OF TAIL POINTER INTO A1
LOAD NEW ENTRY POINTER INTO D2
LOAD POINTER TO HEAD ENTRY INTO D0
IS HEAD POINTER NULL, (0 ENTRIES IN LIST)?
IF SO, WE NEED ONLY TO ESTABLISH POINTERS
PUT HEAD POINTER INTO FORWARD POINTER OF NEW ENTRY
PUT NULL POINTER VALUE INTO D1
PUT NULL POINTER IN BACKWARD POINTER OF NEW ENTRY
LOAD BACKWARD POINTER OF OLD HEAD ENTRY INTO A1
IF WE STILL POINT TO OLD HEAD ENTRY, UPDATE POINTERS
IF NOT, TRY AGAIN
PUT NULL POINTER IN FORWARD POINTER OF NEW ENTRY
PUT NULL POINTER IN BACKWARD POINTER OF NEW ENTRY
IF WE STILL HAVE NO ENTRIES, SET BOTH POINTERS TO THIS ENTRY
IF NOT, TRY AGAIN
SUCCESSFUL LIST ENTRY INSERTION
ENTRY ENTRY ENTRY
+ NEXT + NEXT + NEXT
AFTER INSERTING NEW ENTRY:
+ LAST+ LAST+ LAST
NEW ENTRY LIST_PUT
LIST_GET
LIST_PUT
ENTRY ENTRY
+ NEXT + NEXT+ LAST+ LAST
LIST_GET
ENTRY
+ NEXT+ LAST