home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / utils / asmutl / asmlib.lbr / CONSTR.AZM / CONSTR.ASM
Encoding:
Assembly Source File  |  1991-06-25  |  3.0 KB  |  100 lines

  1. ;----------------------------------------------------------------
  2. ;       This is a module in the ASMLIB library.
  3. ;
  4. ; This module concatenates two strings to produce a second string. 
  5. ; The strings are each preceeded by a length byte and less than 256
  6. ; bytes long. If the result is > 255 bytes long then only enough
  7. ; characters to make up this size in the new string are added.
  8. ; This software comes from 'Z-80 Subroutines By Saville and Leventhal'
  9. ; Modification has been done to make it run under RMAC and to change
  10. ; the parameter passing conventions. DE -> string1, HL -> string 2.
  11. ; B = maximum length of the result string allowed.
  12. ;
  13. ;            Written        R.C.H.        1/10/83
  14. ;            Last Update    R.C.H.        1/10/83
  15. ;----------------------------------------------------------------
  16. ;
  17. ;
  18.     name    'constr'
  19.     public    constr
  20.     maclib    z80
  21. ;
  22. constr:
  23.     xchg                ; Into ASMLIB order
  24. ;
  25. ; Now HL -> string1, DE -> string 2
  26.     shld    s1adr            ; Save string 1 address
  27.     push    b            ; Save maximum length allowed
  28.     mov    a,m            ; Get string 1 length
  29.     sta    s1len            ; Save it
  30.     mov    c,a            ; load into c
  31.     mvi    b,00            ; Clear upper byte
  32.     dad    b            ; Now HL -> last char of string 1
  33.     inx    h            ; Now points past end
  34.     ldax    d            ; Get length of string 2
  35.     sta    s2len            ; Save this too
  36.     inx    d            ; Now de -> character 1 in string 2
  37.     pop    b            ; Restore users max. Length allowed
  38. ;
  39. ; Now we determine how many characters to concatenate.
  40.     mov    c,a            ; Put length of string 2 into C
  41.     lda    s1len            ; Get string 1 length
  42.     add    c            ; Add together
  43.     jrc    toolng            ; Carry and result > 255
  44.     cmp    b            ; Compare to maximum length allowed
  45.     jrz    lenok            ; Ok if of exact size
  46.     jrc    lenok            ; Ok if too small
  47. ;
  48. ; Here and the concatenated string is longer than the allowed length in
  49. ; register b. We indicate a string overflow.
  50. ;
  51. toolng:
  52.     mvi    a,0ffh
  53.     sta    strgov            ; Save the flag
  54.     lda    s1len            ; Get string 1 length back
  55.     mov    c,a            ; Load into C
  56.     mov    a,b            ; Load max length into A
  57.     sub    c            ; take 
  58.     rc                ; Return if original is too long
  59.     sta    s2len            ; Save as new length of string 2
  60.     mov    a,b            ; get maximum again
  61.     sta    s1len            ; Save as new length os string 1
  62.     jr    docat            ; Do the job now, flags etc set.
  63. ;
  64. ; Here and the lengths are ok and we can indicate no overflow.
  65. ;
  66. lenok:
  67.     sta    s1len            ; Save sum of lengths
  68.     sub    a            ; Generate a 0
  69.     sta    strgov            ; Indicate no overflow
  70. ;
  71. ; Here we can concatenate strings by moving characters from string 2
  72. ; to the end of string 1.
  73. ;
  74. docat:
  75.     lda    s2len            ; Get the number of characters
  76.     ora    a
  77.     jrz    exit            ; Exit if nothing to add
  78.     mov    c,a            ; BC = number of characters
  79.     mvi    b,00            
  80.     xchg                ; DE = Destination, HL = source
  81.     ldir                ; Move the characters in a hurry
  82. exit:
  83.     lda    s1len            ; Write new length to string 1
  84.     lhld    s1adr
  85.     mov    m,a            ; Save in memory
  86.     lda    strgov            ; Load overflow flag
  87.     rar                ; Rotate to set flags
  88.     ret
  89. ;
  90.     dseg
  91. s1adr:    db    00,00            ; Address of string 1
  92. s1len:    db    00            ; Length of string 1
  93. s2len:    db    00            ; Length of string 2
  94. strgov:    db    00            ; Overflow flag.
  95.  
  96.     end
  97.  
  98.  
  99.  
  100.