home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / basic / mxadsta.asm < prev    next >
Encoding:
Assembly Source File  |  1989-11-09  |  3.5 KB  |  76 lines

  1. ;***************************** ADDSTRING ********************************
  2. ; This procedure accepts two far strings, concatenates them, and
  3. ; returns the result in the form of a far string.
  4.  
  5.         .model  medium,basic        ;Define memory model to match BASIC.
  6.         .stack
  7.         .data?
  8.         maxst = 50                  ;Maximum bytes reserved for strings
  9. inbuffer1       db  maxst dup(0)    ;Room for first fixed-length string
  10. inbuffer2       db  maxst dup(0)    ;and second one
  11. outbuffer       db  2*maxst dup(0)  ;Work area for string processing
  12.         .data
  13. sh              dd  0               ;Output string descriptor
  14.         .code
  15. addstring   proc    uses si di ds, s1:far ptr, s1len, s2:far ptr, s2len
  16.  
  17. ;First get BASIC to convert BASIC strings into standard form.
  18.         les     ax,s1               ;Push far pointer to
  19.         push    es                  ;input string descriptor.
  20.         push    ax
  21.         xor     ax,ax               ;Push a zero to indicate
  22.         push    ax                  ;it is variable length.
  23.         push    ds                  ;Push far pointer to
  24.         lea     ax, inbuffer1       ;destination string.
  25.         push    ax
  26.         mov     ax,maxst            ;Push length of destination
  27.         push    ax                  ;fixed-length string.
  28.         extrn   stringassign:proc
  29.         call    stringassign        ;Call BASIC to assign variable-length
  30.                                     ;string to fixed-length string.
  31.         les     ax,s2               ;Push far pointer to second
  32.         push    es                  ;input string descriptor.
  33.         push    ax
  34.         xor     ax,ax               ;Push a zero to indicate
  35.         push    ax                  ;it is variable length.
  36.         push    ds                  ;Push far pointer to
  37.         lea     ax,inbuffer2        ;second destination string.
  38.         push    ax
  39.         mov     ax,maxst            ;Push length of destination
  40.         push    ax                  ;fixed-length string.
  41.         extrn   stringassign:proc
  42.         call    stringassign        ;Call BASIC to assign variable-length
  43.                                     ;string to fixed-length string.
  44. ;Concatenate strings.
  45.         lea     si,inbuffer1        ;Copy first string to buffer.
  46.         lea     di,outbuffer
  47.         mov     ax,ds
  48.         mov     es,ax
  49.         mov     cx,s1len
  50.         rep     movsb
  51.         lea     si,inbuffer2        ;Concatenate second string to
  52.         mov     cx,s2len            ;end of first.
  53.         rep     movsb
  54.  
  55. ;Get BASIC to convert result back into a BASIC string.
  56.         push    ds                  ;Push far pointer to fixed-length
  57.         lea     ax,outbuffer        ;result string.
  58.         push    ax
  59.         mov     ax,s1len            ;Compute total length of
  60.         mov     bx,s2len            ;fixed-length result string.
  61.         add     ax,bx
  62.         push    ax                  ;Push length.
  63.         push    ds                  ;Push far pointer to sh (BASIC
  64.         lea     ax,sh               ;will use this in StringAssign).
  65.         push    ax
  66.         xor     ax,ax               ;Push a zero for length
  67.         push    ax                  ;indicating variable-length.
  68.         call    stringassign        ;Call BASIC to assign the
  69.                                     ;result to sh.
  70.         lea     ax,sh               ;Return output string pointer
  71.                                     ;in ax and go back to BASIC.
  72.         ret
  73.  
  74. addstring       endp
  75.                 end
  76.