home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / MSDOS / PKTDRVR / PDCLK207.ZIP / PDCLKSRC / MOVESB.ASM < prev    next >
Encoding:
Assembly Source File  |  1993-08-01  |  1.6 KB  |  66 lines

  1. ; put into the public domain by Russell Nelson, nelson@crynwr.com
  2. ; modified for PDCLKSET usage by Jan Engvald LDC
  3.  
  4. Movesb        proc    near
  5.         test    cs:GenFlags,IS_A_386    ; are we running on a 386?
  6.         jz    MoveMem_86
  7.  
  8.         test    si,2            ; doubleword align
  9.         jz    MemAligned
  10.         cmp    cx,2
  11.         jb    MemAligned
  12.         movsw
  13.         dec    cx
  14.         dec    cx
  15.   MemAligned:
  16.         push    cx            ; transfer all complete dwords.
  17.         .386
  18.         shr    cx,2            ; convert byte count to dword
  19.         rep    movsd
  20.         .8086
  21.         pop    cx
  22.  
  23.         and    cx,3            ; now take take of any trailing
  24.         rep    movsb            ;    words and/or bytes.
  25.         ret
  26. Movesb        endp
  27.  
  28.  
  29.  
  30. MoveMem_86:
  31. ; does the same thing as "rep movsb", only 50% faster.
  32. ; moves words instead of bytes, and handles the case of both addresses odd
  33. ; efficiently.  There is no way to handle one address odd efficiently.
  34. ; This routine always aligns the source address in the hopes that the
  35. ; destination address will also get aligned.  This is from Phil Karn's
  36. ; code from ec.c, a part of his NET package.  I bummed a few instructions
  37. ; out.
  38.         .8086
  39.         jcxz    movemem_cnte        ; If zero, we're done already.
  40.         test    si,1            ; Does source start on odd byte?
  41.         jz    movemem_adre        ; Go if not
  42.         movsb                ; Yes, move the first byte
  43.         dec    cx            ; Count that byte
  44.   movemem_adre:
  45.         shr    cx,1            ; convert to word count
  46.         rep    movsw            ; Move the bulk as words
  47.         jnc    movemem_cnte        ; Go if the count was even
  48.         movsb                ; Move leftover last byte
  49.   movemem_cnte:
  50.         ret
  51.  
  52.  
  53.  
  54. MovesbEsToDs    proc    near
  55.         push    es        ; switch es and ds
  56.         push    ds
  57.         pop    es
  58.         pop    ds
  59.         call    Movesb        ; copy
  60.         push    es        ; switch back es and ds
  61.         push    ds
  62.         pop    es
  63.         pop    ds
  64.         ret
  65. MovesbEsToDs    endp
  66.