home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / diverses / cexpress / strings / chgrange.asm < prev    next >
Encoding:
Assembly Source File  |  1989-05-03  |  1.8 KB  |  64 lines

  1. ;void  change_range(strg,replacement,char_1,char_2);
  2. ;  unsigned char  *strg,replacement,char_1,char_2;
  3.  
  4.     EXTRN  _memory_model:byte
  5.     EXTRN  _error_code:byte
  6.  
  7. _TEXT    SEGMENT BYTE PUBLIC 'CODE'
  8.     ASSUME CS:_TEXT
  9.     PUBLIC _change_range
  10. _change_range proc near
  11.     mov  _error_code,0    ;assume character found
  12.     push bp            ;save bp
  13.     mov  bp,sp        ;set up stack frame
  14.     push di            ;
  15.     push ds            ;
  16.     sub  dx,dx        ;dx > 0 indicates that char found
  17.     cmp  _memory_model,0    ;near or far?
  18.     jle  begin        ;jump if near
  19.     inc  bp            ;else add 2 to BP
  20.     inc  bp            ;
  21. begin:    mov  _error_code,0    ;assume char found
  22.     cmp  _memory_model,2    ;data near or far?
  23.     jb   L0            ;
  24.     les  di,dword ptr[bp+4] ;ES:DI pts to Strg
  25.     inc  bp            ;add 2 to BP since dword ptr
  26.     inc  bp            ;
  27.     jmp  short L00        ;
  28. L0:    mov  ax,ds        ;ES = DS
  29.     mov  es,ax        ;
  30.     mov  di,[bp+4]        ;near case
  31. L00:    mov  ah,[bp+8]        ;get one end of range
  32.     mov  al,[bp+10]        ;get other end of range
  33.     cmp  ah,al        ;compare the values
  34.     jae  L1            ;if above/equal jump ahead
  35.     xchg ah,al        ;else, high value to AH
  36. L1:    cmp  byte ptr es:[di],0    ;test for null string
  37.     je   L4            ;
  38.     mov  bl,[bp+6]        ;keep replacement char in BL
  39. L2:    mov  cl,es:[di]        ;get a character
  40.     cmp  cl,0        ;end of string?
  41.     je   L4            ;
  42.     cmp  cl,ah        ;test against high char
  43.     ja   L3            ;skip ahead if above
  44.     cmp  cl,al        ;test against low char
  45.     jb   L3            ;skip ahead if below
  46.     mov  es:[di],bl        ;change the character
  47.     inc  dx            ;indicate that char found
  48.     mov  _error_code,0    ;character found
  49. L3:    inc  di            ;pt to next char of strg
  50.     jmp  short L2        ;go test next character
  51. L4:    or   dx,dx        ;test if character found
  52.     jnz  L5            ;jump if so
  53.     mov  _error_code,1    ;1 = char not found
  54. L5:    pop  ds            ;
  55.     pop  di            ;
  56.     pop  bp            ;
  57.     cmp  _memory_model,0    ;quit
  58.     jle  quit        ;
  59.     db   0CBh        ;RET far
  60. quit:    ret            ;RET near
  61. _change_range ENDP
  62. _TEXT    ENDS
  63.     END
  64.