home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / pascal / tplib21.zip / INSTALL.EXE / SUTRUNC.ASM < prev    next >
Assembly Source File  |  1993-06-24  |  3KB  |  77 lines

  1. ;               TURBO PASCAL LIBRARY 2.1
  2. ;               Truncate string module
  3.  
  4.                 TITLE   UNIT STRINGS: Truncate string module
  5.                 PAGE    66,132
  6.                 %BIN    12
  7.  
  8. CODE            SEGMENT WORD
  9.                 ASSUME  CS:CODE
  10.                 LOCALS
  11.                 PUBLIC  TRUNCL,TRUNCR
  12.  
  13.  
  14. ;               FUNCTION TruncL (s: STRING; width: BYTE): STRING
  15. ;               Truncate string from left to specified width
  16.  
  17. TRUNCL          PROC    FAR
  18.                 PUSH    BP
  19.                 MOV     BP,SP                   ; Set up stack frame pointer
  20.                 PUSH    DS
  21.                 LDS     SI,[BP+8]               ; Point DS:SI to input string
  22.                 LES     DI,[BP+12]              ; Point ES:DI to output string
  23.                 MOV     AX,[BP+6]               ; Get requested width in AL
  24.                 XOR     AH,AH
  25.                 MOV     CL,[SI]                 ; Get input-string length in CX
  26.                 XOR     CH,CH
  27.                 INC     SI
  28.                 CLD
  29.                 CMP     AL,CL
  30.                 JB      @@L1                    ; Jump if truncation required
  31.                 MOV     AX,CX                   ; If not, copy string as it is
  32.                 JMP     SHORT @@L2
  33. @@L1:           SUB     CX,AX                   ; No. of characters to truncate
  34.                 ADD     SI,CX                   ; Point SI to 1st chr required
  35. @@L2:           STOSB                           ; Store output length
  36.                 MOV     CX,AX                   ; No. of chars. to transfer
  37.                 JCXZ    @@L3
  38.                 REP MOVSB                       ; Copy to output string
  39. @@L3:           POP     DS
  40.                 POP     BP
  41.                 RET     6
  42. TRUNCL          ENDP
  43.  
  44.                 PAGE
  45.  
  46.  
  47. ;               FUNCTION TruncR (s: STRING; width: BYTE): STRING
  48. ;               Truncate string from right to specified width
  49.  
  50. TRUNCR          PROC    FAR
  51.                 PUSH    BP
  52.                 MOV     BP,SP                   ; Set up stack frame pointer
  53.                 PUSH    DS
  54.                 LDS     SI,[BP+8]               ; Point DS:SI to input string
  55.                 LES     DI,[BP+12]              ; Point ES:DI to output string
  56.                 CLD
  57.                 LODSB                           ; Get input-string length in AX
  58.                 XOR     AH,AH
  59.                 MOV     CX,[BP+6]               ; Get requested width in CX
  60.                 XOR     CH,CH
  61.                 CMP     CL,AL                   ; Requested width<input length?
  62.                 JB      @@L1                    ; If not, use input length as
  63.                 MOV     CL,AL                   ; output length
  64. @@L1:           MOV     ES:[DI],CL              ; Store output length
  65.                 INC     DI
  66.                 JCXZ    @@L2                    ; Trap zero-length strings
  67.                 REP MOVSB                       ; Transfer string
  68. @@L2:           POP     DS
  69.                 POP     BP
  70.                 RET     6
  71. TRUNCR          ENDP
  72.  
  73. CODE            ENDS
  74.  
  75.                 END
  76.  
  77.