home *** CD-ROM | disk | FTP | other *** search
- ;**********************************************
- ; type
- ; AnyString = string[255];
- ;
- ; Function RIGHT( S : AnyString;
- ; N : integer;
- ; PAD : Char ) : AnyString;
- ;
- ; Returns a string with S right-justified
- ; in a field of length N. Padding or
- ; truncation on left, as necessary.
- ;
- ;**********************************************
- RIGHT proc near
- push bp
- mov bp,sp
- push ds
- ;
- mov ax,ss ; set up . . .
- mov es,ax ; segment . .
- mov ds,ax ; regs
- lea di,[bp+265] ; first pos of RESULT
- mov ax,[bp+6] ; N
- mov [bp+264],al ; set result length
- mov cl,[bp+8] ; length of S
- xor ch,ch
- lea si,[bp+9] ; first character of S
- add si,cx
- dec si ; last ch of S
- sub ax,cx ; N > l'S?
- ja Pad ; yes, need to pad
- mov cx,[bp+6] ; no, skip pad
- jmp rig2
- ;
- PAD: mov cx,ax ; get length of pad
- mov ax,[bp+4] ; get fill-byte
- cld
- rep stosb ; pad result on left
- mov cl,[bp+8] ; l'S
- ;
- RIG2: add di,cx
- dec di
- std
- rep movsb
- ;
- pop ds
- mov sp,bp
- pop bp
- ret 260 ; clear parameters
- RIGHT endp