home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / PROGRAM / ASM / ALIB30B / STR32.ASM < prev    next >
Assembly Source File  |  1994-12-02  |  2KB  |  91 lines

  1.     page    66,132
  2. ;******************************** STR32.ASM  *********************************
  3.  
  4. LIBSEG           segment byte public "LIB"
  5.         assume cs:LIBSEG , ds:nothing
  6.  
  7. ;----------------------------------------------------------------------------
  8. .xlist
  9.     include  mac.inc
  10.     include  common.inc
  11. .list
  12. ;----------------------------------------------------------------------------
  13.     extrn    strlen1:far
  14.     extrn    strlen2:far
  15. comment 
  16. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -( STRING  )
  17. STR_INSERT - inserts string1 in string2 at specified offset.
  18. ;
  19. ; inputs:    DS:[SI] pointing to string1
  20. ;            ES:[DI] pointing to string2
  21. ;            AX = offset in string2 to insert string1
  22. ;            
  23. ; output:  none
  24. ;
  25. ; note:  The buffer containing string2 must be large enough for
  26. ;        expansion to the size of string1 plus string2.
  27. ;* * * * * * * * * * * * * *
  28. 
  29.     PUBLIC    STR_INSERT,STR_INSERTC
  30. STR_INSERT    PROC    FAR
  31.         APUSH   AX,BX,CX,DX,SI,DI,BP
  32.     call    strlen1        ;
  33.     jmp    str_entry
  34. STR_INSERT    ENDP
  35.  
  36. comment 
  37. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -( STRING  )
  38. STR_INSERTC - inserts string1 in string2 at specified offset.
  39. ;
  40. ; inputs:    DS:[SI] pointing to string1
  41. ;            ES:[DI] pointing to string2
  42. ;            AX = offset in string2 to insert string1
  43. ;            CX = length of string1
  44. ;            
  45. ; output:  none
  46. ;
  47. ; note:  The buffer containing string2 must be large enough for
  48. ;        expansion to the size of string1 plus string2.
  49. ;* * * * * * * * * * * * * *
  50. 
  51.  
  52. STR_INSERTC    proc    far
  53.         APUSH   AX,BX,CX,DX,SI,DI,BP
  54. str_entry:
  55.     mov    dx,cx        ;save length of string1
  56.     call    strlen2
  57.     mov    bp,cx        ;save length of string2
  58. ;
  59. ; make a hole in string2
  60. ;
  61.     push    ds        ;save string1 seg
  62.     push    si        ;save string1 start
  63.  
  64.     push    es
  65.     pop    ds
  66.     
  67.     add    di,bp        ;di points at end of string2
  68.     mov    si,di        ;both si & di point at end of string2
  69.     add    di,dx        ;di points at end of new string
  70.     std
  71.     sub    cx,ax        ;length of move 
  72.     rep    movsb        ;make hole, cx=len of string2
  73. ;
  74. ; ds:si now points at start of hole in string2
  75. ; dx= string1 length  bp=string2 length
  76. ;
  77.     mov    di,si        ;di now points at start of hole
  78.     inc    di
  79.     cld
  80.     pop    si        ;si now points at start of string1
  81.     pop    ds        ;ds now points at string1 seg
  82.     mov    cx,dx        ;get length of string1
  83.     rep    movsb        ;insert string1
  84.     APOP    BP,DI,SI,DX,CX,BX,AX
  85.     RETF
  86. STR_INSERTC    ENDP
  87.  
  88.  
  89. LIBSEG    ENDS
  90.     end
  91.