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

  1. ;               TURBO PASCAL LIBRARY 2.1
  2. ;               Pad string module
  3.  
  4.                 TITLE   UNIT STRINGS: Pad string module
  5.                 PAGE    66,132
  6.                 %BIN    12
  7.  
  8. CODE            SEGMENT WORD
  9.                 ASSUME  CS:CODE
  10.                 LOCALS
  11.                 PUBLIC  PADL, PADR
  12.  
  13.  
  14. ;               FUNCTION PadL (s: STRING; width: BYTE): STRING
  15. ;               Pad string with leading blanks to specified width
  16.  
  17. PADL            PROC    FAR
  18.                 PUSH    BP
  19.                 MOV     BP,SP                   ; Set up stack frame pointer
  20.                 PUSH    DS
  21.                 LDS     SI,DWORD PTR [BP+8]     ; Point DS:SI to input string
  22.                 LES     DI,DWORD PTR [BP+12]    ; Point ES:DI to output string
  23.                 MOV     CX,[BP+6]               ; Get requested width in CX
  24.                 XOR     CH,CH
  25.                 MOV     BX,DI                   ; Keep copy of output address
  26.                 CLD
  27.                 LODSB
  28.                 STOSB                           ; Transfer length to output
  29.                 MOV     DL,AL                   ; Keep input string length
  30.                 CMP     CL,AL
  31.                 JBE     @@L1                    ; Skip if req len<=input length
  32.                 MOV     ES:[BX],CL              ; Store req len as output len.
  33.                 SUB     CL,AL                   ; Calc. no. of blanks to add
  34.                 MOV     AL,20H
  35.                 REP STOSB                       ; Store blanks in output string
  36. @@L1:           MOV     CL,DL
  37.                 XOR     CH,CH                   ; Set CX to input-string length
  38.                 REP MOVSB                       ; Transfer input to output
  39.                 POP     DS                      ; Restore and return
  40.                 POP     BP
  41.                 RET     6
  42. PADL            ENDP
  43.  
  44.                 PAGE
  45.  
  46.  
  47. ;               FUNCTION PadR (s: STRING; width: BYTE): STRING
  48. ;               Pad string with trailing blanks to specified width
  49.  
  50. PADR            PROC    FAR
  51.                 PUSH    BP
  52.                 MOV     BP,SP                   ; Set up stack frame pointer
  53.                 PUSH    DS
  54.                 LDS     SI,DWORD PTR [BP+8]     ; Point DS:SI to input string
  55.                 LES     DI,DWORD PTR [BP+12]    ; Point ES:DI to output string
  56.                 MOV     CL,[SI]
  57.                 XOR     CH,CH                   ; Get input length in CX
  58.                 MOV     DX,CX                   ; Keep copy of input length
  59.                 INC     CX
  60.                 MOV     BX,DI                   ; Keep output length address
  61.                 CLD
  62.                 REP MOVSB                       ; Tranfer input to output
  63.                 MOV     CX,[BP+6]               ; Get requested width in CX
  64.                 XOR     CH,CH
  65.                 CMP     CL,DL
  66.                 JBE     @@L1                    ; Skip if no extra blanks
  67.                 MOV     ES:[BX],CL              ; Store req width as output len
  68.                 SUB     CL,DL                   ; Number of blanks to add in CX
  69.                 MOV     AL,20H
  70.                 REP STOSB                       ; Write blanks to output string
  71. @@L1:           POP     DS                      ; Restore registers
  72.                 POP     BP
  73.                 RET     6
  74. PADR            ENDP
  75.  
  76. CODE            ENDS
  77.  
  78.                 END
  79.  
  80.