home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / msysjour / vol05 / 03 / vlb / vlb.com / LMEMSET.ASM < prev    next >
Assembly Source File  |  1990-04-20  |  1KB  |  56 lines

  1. ;
  2. ;  lmemset      far version of memset
  3. ;
  4.  
  5. INCLUDE         SETUP.H
  6.  
  7. CLIB       SEGMENT  WORD PUBLIC 'CODE'
  8. CLIB       ENDS
  9.  
  10. CLIB        SEGMENT
  11.     ASSUME    CS: CLIB
  12.  
  13. PUBLIC          lmemset
  14.  
  15. lmemset          PROC    FAR
  16.  
  17. Destination     EQU     DWORD   PTR [bp] + 10
  18. FillChar        EQU     BYTE    PTR [bp] + 8
  19. Count           EQU     WORD    PTR [bp] + 6
  20.  
  21.                 ENTRY   0
  22.  
  23.  
  24.             les    di, Destination        ; ES:DI = Destination
  25.             mov    bx, di        ; save a copy of DST
  26.  
  27.             mov    cx, Count
  28.             jcxz    toend        ; if no work to do
  29.  
  30.             mov    al, FillChar    ; the byte FillChar to store
  31.             mov    ah, al        ; store it as a word
  32.  
  33.             test    di, 1        ; is Destination address odd?
  34.             jz    dowords     ;   yes: proceed
  35.  
  36.             stosb            ; store byte for word align
  37.             dec    cx
  38. dowords:
  39.             shr    cx, 1
  40.             rep    stosw        ; store word at a time
  41.             adc    cx, cx
  42.             rep    stosb        ; store final ("odd") byte
  43. toend:
  44.             mov    di, dx        ; Restore DI
  45.  
  46.             xchg    ax, bx        ; AX = Destination
  47.             mov    dx, es        ; segment part of addr
  48.  
  49.                 EXIT    8
  50.  
  51. lmemset          ENDP
  52.  
  53. CLIB          ENDS
  54.  
  55.                 END
  56.