home *** CD-ROM | disk | FTP | other *** search
/ The Unsorted BBS Collection / thegreatunsorted.tar / thegreatunsorted / programming / asm_programming / ASMFILES.ZIP / $INSERT.ASM next >
Assembly Source File  |  1985-06-21  |  2KB  |  49 lines

  1. ;ROUTINE TO INSERT ONE STRING WITHIN ANOTHER                00000100
  2. ;                                    00000200
  3. ;ADDRESSING EQUATES                            00000300
  4. essorc          equ    es:[si]      ;EQUATE FOR SOURCE IN    EXTRA SEGMENT    00000400
  5. dsdest          equ    byte ptr[di]    ;EQUATE    FOR USUAL DESTINATION    00000500
  6. ;                                    00000600
  7. strinsert     proc    far                        00000700
  8. ;                                    00000800
  9.           push    si      ;SAVE    REGISTERS            00000900
  10.           push    di                        00001000
  11.           push    cx                        00001100
  12.           push    ax                        00001200
  13. ;                                    00001300
  14. ;FIND CURRENT END OF DESTINATION STRING                    00001400
  15.           mov    si,bp      ;START OF STRING            00001500
  16.           add    si,es:[si]    ;POINT TO    NEXT TO    LAST BYTE    00001600
  17.           inc    si      ;ADJUST FOR LENGTH INFORMATION    00001700
  18. ;                                    00001800
  19. ;FIND NEW END OF DEST. STRING AND UPDATE LENGTH                00001900
  20.           mov    di,si      ;GET OLD END OF DESTINATION        00002000
  21.           mov    ax,[bx]      ;GET LENGTH OF SOURCE            00002100
  22.           add    di,ax      ;NEW END OF DEST.            00002200
  23.           add    es:[bp],ax    ;NEW LENGTH OF DEST.        00002300
  24. ;                                    00002400
  25. ;MOVE TAIL OF DESTINATION STRING OUT OF    THE WAY                00002500
  26.           mov    cx,si      ;SI-DX+1 IS THE COUNT            00002600
  27.           sub    cx,dx                        00002700
  28.           inc    cx                        00002800
  29.           std          ;BACKWARD DIRECTION            00002900
  30. rep          movs    dsdest,essorc     ;MOVE THE TAIL            00003000
  31. ;                                    00003100
  32. ;MOVE SOURCE STRING INTO PLACE                        00003200
  33.           mov    di,dx      ;DESTINATION OF MOVE            00003300
  34.           mov    si,bx      ;SOURCE OF MOVE            00003400
  35.           cld          ;FORWARD DIRECTION            00003500
  36.           lodsw          ;LENGTH OF SOURCE            00003600
  37.           mov    cx,ax      ;THE COUNT                00003700
  38.           rep    movsb      ;MAKE    THE STRING MOVE            00003800
  39. ;                                    00003900
  40. strinsertexit:                                00004000
  41.           pop    ax      ;RESTORE REGISTERS            00004100
  42.           pop    cx                        00004200
  43.           pop    di                        00004300
  44.           pop    si                        00004400
  45.           ret                            00004500
  46. ;                                    00004600
  47. ;                                    00004700
  48. strinsert     endp                            00004800
  49.