home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / packetdrivers.tar.gz / pd.tar / src / movemem.asm < prev    next >
Assembly Source File  |  1995-06-25  |  2KB  |  69 lines

  1. ;put into the public domain by Russell Nelson, nelson@crynwr.com
  2.  
  3. ;movemem has one of three values: movemem_test, movemem_386, movemem_86.
  4. ;it's initialized to the first, and the code that it points to changes
  5. ;it to the appropriate move routine.
  6.  
  7. ;Some Ethernet boards implement memory that can be accessed only 32 bits
  8. ;at a time.  This code will successfully transfer *from* 32-bit memory
  9. ;even for byte counts not divisible by four.  To use it to transfer *to*
  10. ;32-bit memory, you must first ensure that the count is divisible by four,
  11. ;or do a "rep movsd" if you can afford to write extra bytes.
  12. ;     Also note that it loads an extra dword from the source even if it
  13. ;never uses it.
  14.  
  15.   ifndef is_386
  16.     extrn    is_386: byte        ;=0 if 80[12]8[68], =1 if 80[34]86.
  17.   endif
  18.  
  19. movemem    dw    movemem_test
  20.  
  21. movemem_test:
  22.     cmp    cs:is_386,0        ;Are we running on a 386?
  23.     mov    ax,offset movemem_86
  24.     je    movemem_test_1        ;no.
  25.     mov    ax,offset movemem_386    ;yes, use a 386-optimized move.
  26. movemem_test_1:
  27.     mov    cs:movemem,ax
  28.     jmp    ax
  29.  
  30. movemem_386:
  31. ;transfer all complete dwords.
  32.     push    cx
  33.     db    0c1h, 0e9h, 02h        ;shr cx,2 - convert byte count to dword
  34.     db    066h
  35.     rep    movsw            ;rep movsd
  36.     pop    cx
  37.  
  38. ;now take take of any trailing words and/or bytes.
  39.     db    066h
  40.     push    ax            ;push eax
  41.     db    066h
  42.     lodsw                ;lodsd
  43.  
  44.     test    cx,2
  45.     je    movemem_386_one_word
  46.     stosw
  47.     db    066h, 0c1h, 0e8h, 010h    ;shr    eax,16
  48. movemem_386_one_word:
  49.  
  50.     test    cx,1
  51.     je    movemem_386_one_byte
  52.     stosb
  53. movemem_386_one_byte:
  54.     db    066h
  55.     pop    ax            ;pop eax
  56.     ret
  57.  
  58.  
  59. movemem_86:
  60. ;does the same thing as "rep movsb", only 50% faster.
  61.     shr    cx,1            ; convert to word count
  62.     rep    movsw            ; Move the bulk as words
  63.     jnc    movemem_cnte        ; Go if the count was even
  64.     movsb                ; Move leftover last byte
  65. movemem_cnte:
  66.     ret
  67.  
  68.  
  69.