| Rev | Line |   | 
|---|
| [9] | 1 | !       _strncat()                                      Author: Kees J. Bot
 | 
|---|
 | 2 | !                                                               27 Jan 1994
 | 
|---|
 | 3 | .sect .text; .sect .rom; .sect .data; .sect .bss
 | 
|---|
 | 4 | 
 | 
|---|
 | 5 | ! char *_strncat(char *s1, const char *s2, size_t dx)
 | 
|---|
 | 6 | !       Append string s2 to s1.
 | 
|---|
 | 7 | !
 | 
|---|
 | 8 | .sect .text
 | 
|---|
 | 9 | .define __strncat
 | 
|---|
 | 10 | __strncat:
 | 
|---|
 | 11 |         push    bp
 | 
|---|
 | 12 |         mov     bp, sp
 | 
|---|
 | 13 |         push    si
 | 
|---|
 | 14 |         push    di
 | 
|---|
 | 15 |         mov     di, 4(bp)       ! String s1
 | 
|---|
 | 16 |         mov     cx, #-1
 | 
|---|
 | 17 |         xorb    al, al          ! Null byte
 | 
|---|
 | 18 |         cld
 | 
|---|
 | 19 |   repne scasb                   ! Look for the zero byte in s1
 | 
|---|
 | 20 |         dec     di              ! Back one up (and clear 'Z' flag)
 | 
|---|
 | 21 |         push    di              ! Save end of s1
 | 
|---|
 | 22 |         mov     di, 6(bp)       ! di = string s2
 | 
|---|
 | 23 |         mov     cx, dx          ! Maximum count
 | 
|---|
 | 24 |   repne scasb                   ! Look for the end of s2
 | 
|---|
 | 25 |         jne     no0
 | 
|---|
 | 26 |         inc     cx              ! Exclude null byte
 | 
|---|
 | 27 | no0:    sub     dx, cx          ! Number of bytes in s2
 | 
|---|
 | 28 |         mov     cx, dx
 | 
|---|
 | 29 |         mov     si, 6(bp)       ! si = string s2
 | 
|---|
 | 30 |         pop     di              ! di = end of string s1
 | 
|---|
 | 31 |     rep movsb                   ! Copy bytes
 | 
|---|
 | 32 |         stosb                   ! Add a terminating null
 | 
|---|
 | 33 |         mov     ax, 4(bp)       ! Return s1
 | 
|---|
 | 34 |         pop     di
 | 
|---|
 | 35 |         pop     si
 | 
|---|
 | 36 |         pop     bp
 | 
|---|
 | 37 |         ret
 | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.