home *** CD-ROM | disk | FTP | other *** search
/ Groovy Bytes: Behind the Moon / groovybytes.iso / GROOVY / SND_TOOL / FUNK108A.ZIP / DOS32V30.ZIP / PAL / STRINGS / STRNCPY.ASM < prev    next >
Encoding:
Assembly Source File  |  1995-05-20  |  1.6 KB  |  74 lines

  1. ;****************************************************************************
  2. ; Filename: STRNCPY.ASM
  3. ;   Author: Peter Andersson
  4. ;  Version: 0.0
  5. ;  Created: 1995.03.12
  6. ;  Updated: -
  7. ;****************************************************************************
  8. ; Copyright Peter Andersson, 1994-1995.
  9. ; All rights reserved.
  10. ;****************************************************************************
  11. ; Function: PSZ @strncpy(PSZ dest,PSZ source,ULONG length);
  12. ;  Comment: Copies a string from <source> to <dest> and returns a pointer to
  13. ;           the destination string.
  14. ;    Input: Eax, dest - pointer to destination string
  15. ;           Edx, source - pointer to source string
  16. ;           Ecx, length - maximum length to copy from the source string
  17. ;   Output: pointer to the destination string
  18. ;****************************************************************************
  19.  
  20.     Include    STDDEF.INC
  21.  
  22.     Codeseg
  23.  
  24. Proc    strncpy ,3
  25.         Jecxz    @@Exit06
  26.         Push    Eax,Ebx
  27.         Jmp    @@Next01
  28.     Align    4
  29. @@Loop01:    Add    Eax,4
  30. @@Next01:    Sub    Ecx,4
  31.         Mov    Ebx,[Edx]
  32.         Jbe    @@Exit04
  33.         Add    Edx,4
  34.         TestZ    Bl
  35.         Jz    @@Exit01
  36.         TestZ    Bh
  37.         Jz    @@Exit02
  38.         Test    Ebx,0FF0000h
  39.         Jz    @@Exit03
  40.         TestZ    Ebx,0FF000000h
  41.         Mov    [Eax],Ebx
  42.         Jnz    @@Loop01
  43.         Pop    Ebx,Eax
  44. @@Exit06:    Ret
  45.     Align    4
  46. @@Exit04:    Jz    @@Exit05
  47.         Cmp    Cl,-3
  48.         Je    @@Exit01
  49.         TestZ    Bl
  50.         Je    @@Exit01
  51.         Cmp    Cl,-2
  52.         Je    @@Exit02
  53.         TestZ    Bh
  54.         Je    @@Exit02
  55. @@Exit03:    Mov    [Eax],Bx
  56.         Mov    [Byte Eax+2],0
  57.         Pop    Ebx,Eax
  58.         Ret
  59.     Align    4
  60. @@Exit05:    Mov    [Eax],Ebx
  61.         Pop    Ebx,Eax
  62.         Ret
  63.     Align    4
  64. @@Exit02:    Mov    [Eax],Bx
  65.         Pop    Ebx,Eax
  66.         Ret
  67.     Align    4
  68. @@Exit01:    Mov    [Eax],Bl
  69.         Pop    Ebx,Eax
  70.         Ret
  71. Endp
  72.  
  73.     End
  74.