home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / strings / sounde / sound.asm next >
Encoding:
Assembly Source File  |  1991-03-16  |  3.3 KB  |  133 lines

  1.         PAGE    ,132
  2.         
  3.         TITLE    Soundex Subroutine
  4.  
  5.         COMMENT    $
  6.  
  7.     This subroutine will generate a string of characters representing
  8.     the soundex code for a particular name.  The name is assumed to all
  9.     alphabetic characters, left adjusted in the string addressed by the
  10.     pointer surname.  The output goes into a five byte string sound
  11.     terminated by a zero.  This string is always initialized to: "0000"
  12.     and the fifth byte is set to zero.
  13.     If there is a valid name in surname, the function returns 0.  Otherwise
  14.     it returns 1.  No data storage is used.  SI and DI are used but are
  15.     preserved.  
  16.  
  17.     Reference: Remington-Rand Soundex Code Brochure
  18.     Programmed By A. L.  Bender, M. D.
  19.     PO Box 8685, Woodcliff Lake, NJ 07675-8685
  20.  
  21.  
  22.     This is freely in public domain and may be used without restriction.
  23.     The large model version was tested.
  24.  
  25.     Assemble with:
  26.     masm /Mx /Dlanguage={C||BASIC||PASCAL||FORTRAN} /Dmemmodel={LARGE||MEDIUM||COMPACT||SMALL} sound,,,;
  27.     use:
  28.     extern int soundex(char *output, *input);
  29.     char *input;
  30.     char output[5];
  31.  
  32.     if (soundex(output, input))
  33.         bad exit
  34.     else
  35.         good exit
  36.  
  37.  
  38. Note special adaptations will be needed for Pascal and Basic as well as FORTRAN
  39.  
  40. $
  41. %        .MODEL    memmodel,language
  42.         IF    @DataSize
  43.         .FARDATA
  44.         ELSE
  45.         .DATA
  46.         ENDIF
  47. ;             ABCDEFGHIJKLMNOPQRSTUVWXYZ
  48. sndx        DB    '01230120022455012623010202'
  49.  
  50.         .CODE
  51. soundex        PROC    sound:PTR BYTE, surname:PTR BYTE
  52.         IF    @DataSize
  53.         PUSH    ES
  54.         PUSH    DS
  55.         ENDIF
  56.         PUSH    SI
  57.         PUSH    DI
  58.         PUSHF        
  59.         CLD            ; don't forget this
  60.         IF    @DataSize
  61.         LDS    SI, surname
  62.         LES    DI, sound
  63.         ELSE
  64.         MOV    SI, surname
  65.         MOV    DI, sound
  66.         ENDIF
  67.         MOV    CX,4
  68.         MOV    AX,30H    ;    "0\000"
  69.         push    di    ;    Save DI for the loop guts
  70.         REP STOSB    ;    Clear Destination Area
  71.         MOV    [DI],AH    ;    Add termination character (\000)
  72.         pop    di    ;    Recover destination address
  73.  
  74.         LODSB        ;    Get first letter of the name
  75.         AND    AL,NOT 20H    ;Mask away lower case bit
  76.         CMP    AL,'A'    ;    check for A-Z
  77.         JC    badexit
  78.         CMP    AL,'Z'+1;
  79.         JNC    badexit
  80.         STOSB        ;    First character of name
  81.         MOV    CX,3    ;    Set to store three characters
  82.         MOV    BX,OFFSET sndx    ;set up the XLATB
  83.         MOV    AH,AL    ;    Remember starting character
  84.         IF    @DataSize
  85.         MOV    DX,SEG FAR_DATA
  86.         ENDIF
  87. sloop:        LODSB        ;    get the next character
  88.         CMP    AL,','    ;    break on comma or zero
  89.         JZ    done    ;    finished
  90.         TEST    AL,AL    ;
  91.         JZ    done    ;    EOS done
  92.         CMP    AL,' '    ;    blank
  93.         JZ    sloop    ;    get another character
  94.         CMP    AL,"'"    ;    apostrophe
  95.         JZ    sloop    ;    get another character
  96.         CMP    AL,'-'    ;    dash
  97.         JZ    sloop    ;    get another character
  98.         AND    AL,NOT 20H    ;convert to upper case
  99.         CMP    AL,AH    ;    Is this character the same as the last one?
  100.         JZ    sloop    ;     yes, ignore it - get another character
  101.         MOV    AH,AL    ;    Replace last character with current
  102.         SUB    AL,'A'    ;    Normalize character wrt sound array
  103.         JC    sloop    ;    not alphabetic
  104.         CMP    AL,'Z'-'A'+1    ;check for beyond Z
  105.         JNC    sloop    ;    not A thru Z
  106.         IF    @DataSize
  107.         PUSH    DS
  108.         MOV    DS,DX
  109.         ENDIF
  110.         XLAT        ;    Replace AL with soundex code value
  111.         IF    @DataSize
  112.         POP    DS
  113.         ENDIF
  114.         CMP    AL,'0'    ;    Vowel or non assigned soundex letter
  115.         JZ    sloop    ;    get another character
  116.         STOSB        ;    Insert code into string
  117.         LOOP    sloop    ;    did we do three yet?
  118. done:        XOR    AX,AX    ;    clear ax for good exit        
  119.  
  120. exit:        POPF
  121.         POP    DI
  122.         POP    SI
  123.         IF    @DataSize
  124.         POP    DS
  125.         POP    ES
  126.         ENDIF
  127.         RET
  128.  
  129. badexit:    MOV    AX,1
  130.         JMP    SHORT EXIT
  131. soundex        ENDP
  132.         END
  133.