home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 10.ddi / QUEUE.ZIP / NODE.ASM < prev    next >
Encoding:
Assembly Source File  |  1992-06-10  |  2.5 KB  |  115 lines

  1. ;-------------------------------------
  2. ;-- Define Linked-List Node objects --
  3. ;-------------------------------------
  4.  
  5. MODEL SMALL
  6. LOCALS
  7.  
  8. ;This object is designed to be inherited by any actual data object that is
  9. ;placed in the Linked-List, on the Queue or the Stack defined in this module.
  10.  
  11. ;** Define Linked-List Node object **
  12.  
  13. INCLUDE node.aso
  14.  
  15. ;** Create instance of Linked-List virtual method table **
  16.  
  17. DATASEG
  18.  
  19. TBLINST
  20.  
  21. ;** Define some macros for use by the methods **
  22. ;** These are used by the methods for storing and loading double registers **
  23.  
  24. ;Load two 16-bit registers from an address in specified segment
  25. loadptr macro r2,r1, addr
  26.     mov r2,word ptr [addr+2]
  27.     mov r1,word ptr [addr]
  28.     endm
  29.  
  30. ;** Linked-List Node methods **
  31.  
  32. CODESEG
  33.  
  34. ;Construct (allocate space for) the Node object
  35. ;This is the method "node|construct"
  36. ;This must be a static method
  37. ;Returns AX:BX pointing to allocated but uinitialized node (null if none).
  38. node_construct PROC PASCAL FAR
  39. ARG @@size:word
  40. USES es
  41.     ;-- Allocate memory for the node --
  42.     mov bx,@@size
  43.     add bx,15
  44.     shr bx,4
  45.     mov ah,48h
  46.     int 21h
  47.     jc @@err
  48.     sub bx,bx
  49.     ret
  50. @@err:    sub ax,ax
  51.     sub bx,bx
  52.     ret
  53. ENDP
  54.  
  55. ;Destroy the Node object
  56. ;This is the method "node|destroy"
  57. node_destroy PROC PASCAL FAR
  58. ARG @@node:dword
  59. USES es
  60.     ;-- deallocate memory for the node --
  61.     mov es,word ptr @@node+2
  62.     mov ah,49h
  63.     int 21h
  64.     ret
  65. ENDP
  66.  
  67. ;Initialize the Node object.
  68. ;This is the method "node|init"
  69. node_init PROC PASCAL FAR
  70. ARG @@node:dword
  71. USES ds,bx
  72.     lds bx,@@node
  73.     ;-- Initialize any virtual method table for the object at ds:bx --
  74.     TBLINIT ds:bx
  75.     ;-- Initialize the object's data --
  76.     sub ax,ax
  77.     mov word ptr ds:[bx.node_next],ax
  78.     mov word ptr ds:[bx.node_next+2],ax
  79.     mov word ptr ds:[bx.node_prev],ax
  80.     mov word ptr ds:[bx.node_prev+2],ax
  81.     ret
  82. ENDP
  83.  
  84. ;Deinitialize the Node object.
  85. ;This is the method "node|deinit"
  86. node_deinit PROC PASCAL FAR
  87. ARG @@node:dword
  88.     ;does nothing.
  89.     ret
  90. ENDP
  91.  
  92. ;Advance to the next node in the linked-list of node objects.
  93. ;This is the method "node|next"
  94. ;Returns DX:AX pointing to next node, null if none.
  95. node_adv PROC PASCAL NEAR
  96. ARG @@node:dword
  97. USES ds,si
  98.     lds si,@@node
  99.     loadptr dx,ax, ds:si.node_next
  100.     ret
  101. ENDP
  102.  
  103. ;Backup to the previous node in the linked-list of node objects.
  104. ;This is the method "node|prev"
  105. ;Returns DX:AX pointing to previous node, null if none.
  106. node_back PROC PASCAL NEAR
  107. ARG @@node:dword
  108. USES ds,si
  109.     lds si,@@node
  110.     loadptr dx,ax, ds:si.node_prev
  111.     ret
  112. ENDP
  113.  
  114. END
  115.