146
K
A
DAK
AMX Linked List Manager
USER_CODE SEGMENT BYTE 'CODE' ;Code segment
;ASSUME CS:USER_CODE, DS:USER_DATA, ES:USER_DATA
;EXTRN RANDOM:FAR ;Random number generator
;
EXAMPLE PROC FAR
MOV AX,SEG USER_DATA
MOV DS,AX ;Assure data access
MOV ES,AX
;MOV CX,KEYNODE-(BYTE PTR ID) ;Offset to key node
MOV SI,OFFSET KEYLIST ;A(Keyed list)
CALL AALCRE ;Create keyed list
;MOV CX,LISTNODE-(BYTE PTR ID) ;Offset to list node
MOV SI,OFFSET EXTLIST ;A(Extraction list)
CALL AALCRE ;Create extraction list
;MOV SI,OFFSET KEYLIST ;A(keyed list)
MOV BX,OFFSET OBJARRAY ;A(first object)
MOV DI,1 ;i = 1
;
EXLP1: MOV [BX].ID,DI ;Install object id
CALL RANDOM ;AX = random number
MOV CX,AX ;CX = key
; ;ES:BX = A(object)
CALL AALINSK ;Insert in random order
ADD BX,OBJSIZ ;Next object
INC DI ;i++
CMP DI,NUMOBJ
JLE EXLP1 ;More to go
CALL AALHEAD ;ES:BX = head of list
EXLP2: MOV AX,ES
OR AX,BX
JZ EXEND ;End of keyed list
CMP ES:[BX].ID,6
JE EXFND ;Found object of interest
CALL AALNEXT ;ES:BX = next object
JMP SHORT EXLP2
;
EXFND: CALL AALRMVC ;Remove object from list
MOV SI,OFFSET EXTLIST ;A(Extraction list)
CALL AALINST ;Add to tail of list
EXEND: RET
;
EXAMPLE ENDP
;
USER_CODE ENDS ;End of code segment