home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / CRUNCH10.ZIP / LOOKUP.ASM < prev    next >
Encoding:
Assembly Source File  |  1988-11-05  |  4.1 KB  |  78 lines

  1. ;
  2. ; Lookup an entry in the Hash Table.  If found, return TRUE and set the VAR
  3. ; parameter FoundAt with the index of the entry at which the match was found.
  4. ; If not found, return FALSE, and add unmatched prefix/suffix to end of table.
  5. ;
  6. ;
  7. ; Register usage:
  8. ;   AX - varies                     BL - holds target suffix character
  9. ;                                   BH - If search fails, determines how to
  10. ;                                        add the new entry
  11. ;   CX - not used                   DX - holds size of 1 table entry (5)
  12. ;   DI - varies                     SI - holds offset of 1st table entry
  13. ;   ES - seg addr of hash table     DS - program's data segment
  14. ;
  15. ;
  16.             mov byte    bl,[bp+<TargetSuffix]   ;Target Suffix character
  17.             mov word    ax,[bp+<TargetPrefix]   ;Index into table
  18.             mov         dx,5                    ;5 byte table entries
  19.             mul         dx                      ;AX now an offset into table
  20.             les         di,[>HashTable]         ;Hash table address
  21.             mov         si,di                   ;save offset in SI
  22.             add         di,ax                   ;es:di points to table entry
  23. ;
  24.             mov         bh,0                    ;Chain empty flag (0=empty)
  25.         es: cmp word    [di],-1                 ;Anything on the chain?
  26.             jz          NotFound                ;Nope, search fails
  27.             mov         bh,1                    ;Chain empty flag (1=not empty)
  28. ;
  29.         es: mov word    ax,[di]                 ;Get index of 1st entry in chain
  30. Loop:       mov word    [bp+<TargetPrefix],ax   ;Save index for later
  31.             mov         dx,5
  32.             mul         dx                      ;convert index to offset
  33.             mov         di,si                   ;es:di points to start of table
  34.             add         di,ax                   ;es:di points to table entry
  35. ;
  36.         es: cmp byte    bl,[di+4]               ;match on suffix?
  37.             jz          Found                   ;Yup, search succeeds
  38. ;
  39.         es: cmp word    [di+2],-1               ;any more entries in chain?
  40.             jz          NotFound                ;nope, search fails
  41. ;
  42.         es: mov word    ax,[di+2]               ;get index of next chain entry
  43.             jmp short   Loop                    ;   and keep searching
  44. ;
  45. Found:      mov byte    [bp-1],1                ;return TRUE
  46.             les         di,[bp+<FoundAt]        ;get address of Var parameter
  47.             mov word    ax,[bp+<TargetPrefix]   ;get index of entry where found
  48.         es: mov         [di],ax                 ;and store it
  49.             jmp short   Done
  50. ;
  51. NotFound:   mov word    ax,[>FreeEntry]         ;Index of next free table entry
  52.             cmp word    ax,>Tablesize           ;Any room in table
  53.             jb          NotFull                 ;Yes
  54.             mov byte    [>TableFull],1          ;Set flag
  55.             jmp short   SkipAdd                 ;Exit without adding entry
  56. NotFull:    cmp         bh,0                    ;Adding new entry
  57.             jz          First                   ;New entry is 1st one in the chain
  58.         es: mov         [di+2],ax               ;Append new entry to chain
  59.             jmp short   InitNew
  60. First:  es: mov         [di],ax                 ;New entry is 1st one in chain
  61. InitNew:    mov         dx,5
  62.             mul         dx                      ;ax = offset of new entry in table
  63.             mov         di,si
  64.             add         di,ax                   ;es:di points at new entry
  65.             mov         ax,-1
  66.             cld
  67.             stosw                               ;Init FIRST ptr to -1
  68.             stosw                               ;Init NEXT ptr to -1
  69.             mov         al,bl                   ;al=suffix for this new entry
  70.             stosb                               ;Init SUFFIX field
  71.             inc word    [>FreeEntry]            ;point FreeEntry to next empty slot
  72. SkipAdd:    mov byte    [bp-1],0                ;return FALSE
  73.             les         di,[bp+<FoundAt]        ;get address of Var parameter
  74.         es: mov word    [di],-1                 ;and store a -1 in it
  75. ;
  76. Done:
  77. ;
  78.