home *** CD-ROM | disk | FTP | other *** search
- ;void pad_left(strg,ch,length);
- ; unsigned char *strg,ch;
- ; unsigned short length;
-
- EXTRN _memory_model:byte
- EXTRN _error_code:byte
-
- _TEXT SEGMENT BYTE PUBLIC 'CODE'
- ASSUME CS:_TEXT
- PUBLIC _pad_left
- _pad_left proc near
- push bp ;
- mov bp,sp ;set up stack frame
- push di ;
- push si ;
- push ds ;save DS
- mov _error_code,1 ;1 = error
- cmp _memory_model,0 ;near or far?
- jle begin ;jump if near
- inc bp ;else add 2 to BP
- inc bp ;
- begin: cmp _memory_model,2 ;data near or far?
- jb L0 ;jump if near
- les di,dword ptr[bp+4] ;get string address
- mov ax,es ;DS = ES
- mov ds,ax ;
- inc bp ;add 2 to bp since dword ptr
- inc bp ;
- jmp short L1 ;jump ahead
- L0: mov di,[bp+4] ;near case
- mov ax,ds ;
- mov es,ax ;
- L1: sub cx,cx ;must find string length
- mov si,di ;copy string ptr
- L2: cmp byte ptr[si],0 ;end of string?
- je L3 ;
- inc si ;
- inc cx ;
- jmp short L2 ;loop till null
- L3: sub bx,bx ;
- mov bl,[bp+8] ;new string length in BL
- cmp cl,bl ;compare the two lengths
- jae L5 ;quit if old len >= new
- add di,bx ;pt DI to new string end
- sub bx,cx ;number of spaces to pad
- inc cx ;move extra char for null
- std ;set direction flag
- rep movsb ;move old string right
- mov cx,bx ;spaces to pad in CX
- mov al,[bp+6] ;get pad character
- L4: mov es:[di],al ;insert pad char
- dec di ;move to next position
- loop L4 ;go do next char
- pop ds ;restore DS
- dec _error_code ;0 = no error
- jmp short L6 ;jump ahead and quit
- L5: pop ds ;exit with error
- L6: pop si ;
- pop di ;
- pop bp ;
- cld ;
- cmp _memory_model,0 ;quit
- jle quit ;
- db 0CBh ;RET far
- quit: ret ;RET near
- _pad_left ENDP
- _TEXT ENDS
- END