home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / utils / asmutl / asmlib.lbr / EBLSTR.AZM / EBLSTR.ASM
Encoding:
Assembly Source File  |  1991-06-25  |  2.3 KB  |  95 lines

  1. ;----------------------------------------------------------------
  2. ;          This is a module in the ASMLIB library
  3. ;
  4. ; This module eliminates blanks from both the start and the 
  5. ; finish of strings. This is handy for free format scanners
  6. ; which may return a series of blanks on a string.
  7. ;
  8. ; Entry points are.
  9. ;
  10. ; ELBSTR   -- Eliminate leading blanks from a string. DE -> string
  11. ; ETBSTR   -- Eliminate trailing blanks, DE -> string.
  12. ;
  13. ;            Written      R.C.H.      1/11/83
  14. ;            Last Update  R.C.H.      1/11/83
  15. ;----------------------------------------------------------------
  16. ;
  17. ;
  18.     name    'eblstr'
  19.     public    elbstr,etbstr
  20.     extrn    delstr
  21.     maclib    z80
  22. ;
  23. ; Eliminate leading blanks by counting them and then shifting the 
  24. ; the string back to cover them then adjust the string size.
  25. ;
  26. elbstr:
  27.     ldax    d
  28.     ora    a
  29.     rz            ; exit if zero sized string
  30.     sded    str$adr        ; save its address
  31.     mov    b,a        ; save size as a counter
  32.     mov    c,a        ; save a copy
  33. elb$loop:
  34.     inx    d
  35.     ldax    d        ; get a character from the string
  36.     cpi    ' '        ; is it a blank ?
  37.     jrnz    elb$nob
  38.     djnz    elb$loop
  39. ; Here and all characters in the string are blanks
  40.     xra    a
  41.     lded    str$adr
  42.     stax    d
  43.     ret
  44. ;
  45. ; Here and there was a character found that was not a blank in the string
  46. ; so we can now shift the string back and reset the string length
  47. ;
  48. elb$nob:
  49.     mov    a,c        ; get the original length
  50.     sub    c        ; subtract the current count
  51.     jrz    elb$end
  52. ;
  53.     mvi    c,01        ; start at character 1
  54.     mov    b,a        ; 2 = characters to delete
  55.     call    delstr        ; delete the characters
  56. ;
  57. elb$end:
  58.     lded    str$adr
  59.     ret
  60. ;
  61. ; This routine eliminates trailing characters from a string by
  62. ; finding how many characters there are in the string then adjusting
  63. ; till no blanks are present at the end.
  64. ;
  65. etbstr:
  66.     ldax    d
  67.     ora    a
  68.     rz
  69.     push    h
  70.     push    d        ; save start address
  71.     mov    l,a        ; load character count
  72.     mvi    h,00        ; clear top
  73.     dad    d        ; now hl -> last character
  74.     mov    b,a        ; load a counter
  75. etb$loop:
  76.     mov    a,m
  77.     cpi    ' '
  78.     jrnz    etb$end
  79.     dcx    h
  80.     djnz    etb$loop
  81. ;
  82. etb$end:
  83.     pop    h        ; get start address into hl
  84.     mov    m,b        ; save string length
  85.     xchg            ; load string address into de
  86.     pop    h        ; restore original hl
  87.     ret
  88. ;
  89.     dseg
  90. str$adr    db    00
  91.     end
  92.  
  93.  
  94.  
  95.