Motorola M68000 User's Guide Page 132

  • Download
  • Add to my manuals
  • Print
  • Page
    / 256
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 131
118 Assembly Language Programming for the 68000 Family
in the correct location. There are many ways to obtain the storage for
a node. One way is to maintain a linked list of free nodes. All we have
to do is to initialize this linked list by chaining the nodes together. For
our example we will have nodes of size NDATA. This represents a node
of size NDATA+4, where NDATA is the size of the data in the node.
A header, FLIST, will be maintained that will point to the pool of free
nodes. Assuming the total number of nodes is equal to the value of symbol
NNODES the following subroutine, INIT, will initialize a free list of
nodes:
NDATAs EQU 10 10 BYTES OP DATA (MUST BE EVEN NO.)
NSIZE: EQU NDATA+4 DATA + POINTER
NNODES: EQU 100 NUMBER OF NODES
** * * * ** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* INIT - INITIALIZE THE FREE LIST
** * * * ** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
INIT:
MOVEM.L
D1/A0-A1,-(SP)
SAVE REGS
LEA
NODES,A0
A0 -> NODE POOL
LEA
FLIST,A1
Al -> HEADER OF FREE LIST
MOVE.W
#NNODES-l,D1 SET UP FOR LOOP
INIT1:
MOVE.L
A0,(Al)
SET -> TO NEXT NODE
MOVEA.L A0 ,A1
SET UP FOR NEXT NDOE
ADDA.L
#NSIZE,A0
A0 -> NEXT NODE
DBRA
Dl ,INIT1
LOOP UNTIL DONE
CLR.L (Al)
PLACE NULL PTR IN LAST NODE
MOVEM.L
(SP)+,D0/A0-A1
RESTORE REGS
*
RTS
DATA
FLIST: DS.L
1
-> FREE LIST
NODES:
DS.B
NSIZE*NNODES
NODE POOL
The CLR.L instruction places a zero value in the very last pointer. A
value of zero is used to represent the NULL pointer. We can never have
a node at address zero for reasons that will be covered in Chapter 12.
Locations starting at zero are special reserved locations on the 68000.
Our next step is to write a subroutine that will obtain a free node from
this free list. Here is how we do it:
******************************************************
* GETFREE - RETURNS PTR TO FREE NODE IN A0.
* IF NO NODES LEFT, NULL IS RETURNED
* * * * * * * * * * * * * * * * * * * * * * * * * * *
GETFREE:
MOVEA.L FLIST,A0
CMPA.L #0,A0
BEQ GETFRET
MOVE.L (A0),FLIST
GETFRET:RTS
* * * * * * * * * * * * * * * * * * * * * *
GET HEAD PTR
NULL?
YES, JUST RETURN
NO, SET NEW HEAD
Page view 131
1 2 ... 127 128 129 130 131 132 133 134 135 136 137 ... 255 256

Comments to this Manuals

No comments