Motorola MC68030 User Manual page 105

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

Advertisement

The next code (see Figure 3–3) fragment shows the use of a CAS2 instruction to delete an
element from a linked list. The first LEA instruction loads the effective address of HEAD into
A0. The MOVE instruction loads the address in pointer HEAD into D0. The TST instruction
checks for an empty list, and the BEQ instruction branches to a routine at label SDEMPTY
if the list is empty. Otherwise, a second LEA instruction loads the address of the NEXT
pointer in the newest element on the list into A1, and the following MOVE instruction loads
the pointer contents into D1. The CAS2 instruction compares the address of the newest
structure to the value in HEAD and the address in D1 to the pointer in the address in A1. If
no element has been inserted or deleted by another routine while this routine has been
executing, the results of these comparisons are equal, and the CAS2 instruction stores the
new value into location HEAD. If an element has been inserted or deleted, the CAS2
instruction loads the new address in location HEAD into D0, and the BNE instruction
branches to the TST instruction to try again.
SDELETE
LEA
MOVE.L
SDLOOP
TST.L
BEQ
LEA
MOVE.L
CAS2.L
BNE
SDEMPTY
BEFORE DELETING AN ELEMENT:
HEAD
AFTER DELETING AN ELEMENT:
HEAD
MOTOROLA
HEAD, A0
LOAD ADDRESS OF HEAD POINTER INTO A0
(A0), D0
MOVE VALUE OF HEAD POINTER INTO D0
D0
CHECK FOR NULL HEAD POINTER
SDEMPTY
IF EMPTY, NOTHING TO DELETE
(NEXT, D0), A1
LOAD ADDRESS OF FORWARD LINK INTO A1
(A1), D1
PUT FORWARD LINK VALUE IN D1
D0:D1, D1:D1, (A0):(A1)
IF STILL POINT TO ENTRY TO BE DELETED, THEN UPDATE HEAD
AND FORWARD POINTERS
SDLOOP
IF NOT, TRY AGAIN
SUCCESSFUL DELETION, ADDRESS OF DELETED ENTRY IN D0
(MAY BE NULL)
ENTRY
+ NEXT
ENTRY
+ NEXT
Figure 3-3. Linked List Deletion
MC68030 USER'S MANUAL
Instruction Set Summary
ENTRY
+ NEXT
ENTRY
+ NEXT
ENTRY
+ NEXT
ENTRY
+ NEXT
3-27

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents