home *** CD-ROM | disk | FTP | other *** search
- ;***********************************************************
- ;
- ; RightStr.ASM - A FAR PROC for use in a TP4 unit as
- ;
- ; function RightStr(_S : String; Number : Word) : String;
- ;
- ; returns all the characters starting at Number to the
- ; end of string. A NULL string is returned if Number is
- ; greater than the length of _S, or if _S = '', or if
- ; Number = 0.
- ; ex.
- ; the pascal line
- ;
- ; S := RightStr('hello world',7);
- ; the variable S now contains the value
- ; 'world'
- ;
- ; Note: since this routine is written for use in a Turbo
- ; Pascal 4 program, they do not preserve AX,BX,CX,DX.ES,
- ; DI,SI. Turbo Pascal does not require that we save these
- ; registers, so to speed things up, we don't! As always,
- ; BP,DS are preserved.
- ;
- ;
- ;***********************************************************
-
- INCLUDE MACROS.ASM
-
-
- CODE SEGMENT BYTE PUBLIC
- ASSUME CS:CODE
-
- PUBLIC RightStr
-
- ; The parameters: TP4 always push the FunctionRes address first.
- ; Then comes the _S : String, forllowed by Number : Word.
- ; We declare this as far for use in a unit
-
- FunctionRes EQU DWORD PTR [BP+0Ch]
- _S EQU DWORD PTR [BP+08h]
- Number EQU [BP+06h]
-
- ; if this function is to be used in the interface section of a
- ; unit, then FAR is correct. Otherwise, if you need or want
- ; to use this function differently, you must understand how
- ; TP4 decides what size pointer to call a routine with, as
- ; well as how to adjust the paraneters on the stack to
- ; correspond to the proper PROC declaration. This will be
- ; covered shortly in another upload.
-
- RightStr PROC FAR
- StandEntry
- MOV DX,DS
-
- StringOps _S,FunctionRes,FORWARD
-
- MOV CX,Number ; starting position in str
- XOR CH,CH ; zero out high byte of CX
-
- JCXZ ReturnNullStr ; if CX = 0 then nothing to do
-
- LODSB ; get length of _S
- CMP AL,CL ; compare it to Number
- JB ReturnNullStr ; Number > Length(S) so ret ''
-
- SUB AL,CL ; sub Number from Length(_S)
-
- XOR AH,AH ; zero out high byte of AX
- MOV BX,CX ; copy Length(S) to BX
- DEC BX ; subtract 1
-
- ADD SI,BX ; add BX to offset of _S
-
- INC AL
-
- MOV CL,AL ; copy length to CL
-
- STOSB ; store length of result
-
- REP MOVSB ; copy CL chars
- JMP SHORT ExitCode ; all done
-
- ReturnNullStr:
- XOR AL,AL
- STOSB
-
- ExitCode:
- MOV DS,DX
- StandExit 06h
- RightStr ENDP
-
- CODE ENDS
-
- END