home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Media Share 9
/
MEDIASHARE_09.ISO
/
pascal
/
tplib21.zip
/
INSTALL.EXE
/
SUTRUNC.ASM
< prev
next >
Wrap
Assembly Source File
|
1993-06-24
|
3KB
|
77 lines
; TURBO PASCAL LIBRARY 2.1
; Truncate string module
TITLE UNIT STRINGS: Truncate string module
PAGE 66,132
%BIN 12
CODE SEGMENT WORD
ASSUME CS:CODE
LOCALS
PUBLIC TRUNCL,TRUNCR
; FUNCTION TruncL (s: STRING; width: BYTE): STRING
; Truncate string from left to specified width
TRUNCL PROC FAR
PUSH BP
MOV BP,SP ; Set up stack frame pointer
PUSH DS
LDS SI,[BP+8] ; Point DS:SI to input string
LES DI,[BP+12] ; Point ES:DI to output string
MOV AX,[BP+6] ; Get requested width in AL
XOR AH,AH
MOV CL,[SI] ; Get input-string length in CX
XOR CH,CH
INC SI
CLD
CMP AL,CL
JB @@L1 ; Jump if truncation required
MOV AX,CX ; If not, copy string as it is
JMP SHORT @@L2
@@L1: SUB CX,AX ; No. of characters to truncate
ADD SI,CX ; Point SI to 1st chr required
@@L2: STOSB ; Store output length
MOV CX,AX ; No. of chars. to transfer
JCXZ @@L3
REP MOVSB ; Copy to output string
@@L3: POP DS
POP BP
RET 6
TRUNCL ENDP
PAGE
; FUNCTION TruncR (s: STRING; width: BYTE): STRING
; Truncate string from right to specified width
TRUNCR PROC FAR
PUSH BP
MOV BP,SP ; Set up stack frame pointer
PUSH DS
LDS SI,[BP+8] ; Point DS:SI to input string
LES DI,[BP+12] ; Point ES:DI to output string
CLD
LODSB ; Get input-string length in AX
XOR AH,AH
MOV CX,[BP+6] ; Get requested width in CX
XOR CH,CH
CMP CL,AL ; Requested width<input length?
JB @@L1 ; If not, use input length as
MOV CL,AL ; output length
@@L1: MOV ES:[DI],CL ; Store output length
INC DI
JCXZ @@L2 ; Trap zero-length strings
REP MOVSB ; Transfer string
@@L2: POP DS
POP BP
RET 6
TRUNCR ENDP
CODE ENDS
END