home *** CD-ROM | disk | FTP | other *** search
- ;void change_range(strg,replacement,char_1,char_2);
- ; unsigned char *strg,replacement,char_1,char_2;
-
- EXTRN _memory_model:byte
- EXTRN _error_code:byte
-
- _TEXT SEGMENT BYTE PUBLIC 'CODE'
- ASSUME CS:_TEXT
- PUBLIC _change_range
- _change_range proc near
- mov _error_code,0 ;assume character found
- push bp ;save bp
- mov bp,sp ;set up stack frame
- push di ;
- push ds ;
- sub dx,dx ;dx > 0 indicates that char found
- cmp _memory_model,0 ;near or far?
- jle begin ;jump if near
- inc bp ;else add 2 to BP
- inc bp ;
- begin: mov _error_code,0 ;assume char found
- cmp _memory_model,2 ;data near or far?
- jb L0 ;
- les di,dword ptr[bp+4] ;ES:DI pts to Strg
- inc bp ;add 2 to BP since dword ptr
- inc bp ;
- jmp short L00 ;
- L0: mov ax,ds ;ES = DS
- mov es,ax ;
- mov di,[bp+4] ;near case
- L00: mov ah,[bp+8] ;get one end of range
- mov al,[bp+10] ;get other end of range
- cmp ah,al ;compare the values
- jae L1 ;if above/equal jump ahead
- xchg ah,al ;else, high value to AH
- L1: cmp byte ptr es:[di],0 ;test for null string
- je L4 ;
- mov bl,[bp+6] ;keep replacement char in BL
- L2: mov cl,es:[di] ;get a character
- cmp cl,0 ;end of string?
- je L4 ;
- cmp cl,ah ;test against high char
- ja L3 ;skip ahead if above
- cmp cl,al ;test against low char
- jb L3 ;skip ahead if below
- mov es:[di],bl ;change the character
- inc dx ;indicate that char found
- mov _error_code,0 ;character found
- L3: inc di ;pt to next char of strg
- jmp short L2 ;go test next character
- L4: or dx,dx ;test if character found
- jnz L5 ;jump if so
- mov _error_code,1 ;1 = char not found
- L5: pop ds ;
- pop di ;
- pop bp ;
- cmp _memory_model,0 ;quit
- jle quit ;
- db 0CBh ;RET far
- quit: ret ;RET near
- _change_range ENDP
- _TEXT ENDS
- END