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

  1. ;void  over_write(strg,sub_strg,position);
  2. ;  char  *strg,*sub_strg;
  3. ;  unsigned short  position;
  4.  
  5.     EXTRN  _memory_model:byte
  6.     EXTRN  _error_code:byte
  7.  
  8. _TEXT    SEGMENT BYTE PUBLIC 'CODE'
  9.     ASSUME CS:_TEXT
  10.     PUBLIC _over_write
  11. _over_write proc near
  12.     mov  _error_code,0    ;assume no error
  13.     push bp            ;
  14.     mov  bp,sp        ;set up stack frame
  15.     push di            ;
  16.     push si            ;
  17.     push ds            ;DS is changed
  18.     cmp  _memory_model,0    ;near or far?
  19.     jle  begin        ;jump if near
  20.     inc  bp            ;else add 2 to BP
  21.     inc  bp            ;
  22. begin:    sub  cx,cx        ;
  23.     cmp  _memory_model,2    ;data near or far?
  24.     jb   L0            ;jump if near    
  25.     les  di,dword ptr [bp+4]  ;ES:DI pts to Strg
  26.     lds  si,dword ptr [bp+8]  ;DS:SI pts to substring
  27.     mov  cx,[bp+12]        ;position    
  28.     jmp  short L1        ;
  29. L0:    mov  di,[bp+4]        ;NEAR case
  30.     mov  si,[bp+6]        ;
  31.     mov  cx,[bp+8]        ;
  32.     mov  ax,ds        ;ES = DS
  33.     mov  es,ax        ;
  34. L1:    add  di,cx        ;forward ptr to position
  35.     cld            ;
  36. L2:    lodsb            ;get a char
  37.     cmp  al,0        ;end of string?
  38.     je   L3            ;quit if so
  39.     stosb            ;
  40.     jmp  short L2        ;loop
  41. L3:    pop  ds            ;restore DS
  42.     pop  si            ;
  43.     pop  di            ;
  44.     pop  bp            ;
  45.     cmp  _memory_model,0    ;quit
  46.     jle  quit        ;
  47.     db   0CBh        ;RET far
  48. quit:    ret            ;RET near
  49. _over_write ENDP
  50. _TEXT    ENDS
  51.     END
  52.