home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / dtx9302 / ctrick / 386mem.asm next >
Encoding:
Assembly Source File  |  1993-03-05  |  5.9 KB  |  196 lines

  1. ;* ****************************************************** *
  2. ;*                    386MEM.ASM                          *
  3. ;*            (c) 1993 Holger Suhr & DMV                  *
  4. ;* ****************************************************** *
  5.  
  6. ;* ****************************************************** *
  7. ;*  Die nachfolgenden Funktionen erlauben das Kopieren    *
  8. ;*  und Füllen von Speicherflächen mit Unterstützung der  *
  9. ;*  386-Funktionen REP MOVSD bzw.  REP STOSD, die         *
  10. ;*  bei gleichem Zeitbedarf jeweils 4 Byte                *
  11. ;*  kopieren/füllen                                       *
  12. ;*  Vorausgesetzt wird, daß die Speicherflaeche auf       *
  13. ;*  4-Byte-Boundary ausgelegt ist, da nur dann der volle  *
  14. ;*  Geschwindigkeitsgewinn zum Tragen kommt               *
  15. ;*                                                        *
  16. ;*  Eben aus diesem Grund werden ungerade Bytes und       *
  17. ;*  ungerade Worte zuletzt kopiert/gefüllt                *
  18. ;* ****************************************************** *
  19.  
  20. ; Standard Turbo-C include-file
  21. ; erlaubt die Beschreibung von Sourcen, die über alle
  22. ; Speichermodelle gültig sind
  23.  
  24. INCLUDE RULES.ASI
  25.  
  26. PLUS    =   0
  27.  
  28. IF LPROG
  29. ; bei LARGE-Code-Modellen liegt der erste Parameter
  30. ; 2 byte tiefer auf dem Stack, da das Code-Segment
  31. ; beim call gesichert wird.
  32.  
  33.     PLUS    =   2
  34. ENDIF
  35.  
  36.  
  37. ExtSym@     _cpu386,WORD,__CDECL__
  38.  
  39. CSeg@
  40.  
  41.  
  42. ;* ******************************************************* *
  43. ;*  void hswap(void *DEST,void *SRCE,int anz)              *
  44. ;*                                                         *
  45. ;*  copy BYTE array to BYTE array                          *
  46. ;*                                                         *
  47. ;* ******************************************************* *
  48.  
  49. PubProc@    hswap,__CDECL__
  50.  
  51.     push    bp
  52.     mov     bp,sp
  53.     push    si
  54.     push    di
  55.     push    ds               ; ds wird evtl. verändert
  56.  
  57. IF LDATA
  58. ; bei LARGE-Data Modellen werden 4-Byte-Pointer übergeben
  59.  
  60.     les     di,dword ptr [bp+4+PLUS]    ; destination
  61.     lds     si,dword ptr [bp+8+PLUS]    ; source
  62.     mov     cx,word ptr [bp+12+PLUS]    ; anzahl bytes
  63. ELSE
  64.     push    ds               ; in NEAR-Data-Modellen liegen
  65.     pop     es               ; Source und Destination im DS
  66.     mov     di,word ptr [bp+4+PLUS]     ; destination
  67.     mov     si,word ptr [bp+6+PLUS]     ; source
  68.     mov     cx,word ptr [bp+8+PLUS]     ; anzahl bytes
  69. ENDIF
  70.  
  71.     jcxz    wcop5            ; nichts zu tun ??
  72.     shr     cx,1             ; bytes /2 == worte
  73.     pushf                    ; ungerade bytes ? im carryflag
  74.  
  75. wcop0:
  76.     jcxz    wcop4            ; keine worte ? dann carrytest1
  77.     test    __cpu386,1       ; 386-er vorhanden ?
  78.     jz      wcop2            ; leider nicht
  79.  
  80. .386
  81.     shr     cx,1             ; worte /2 == dwords
  82.     pushf                    ; ungerade words ? im carryflag
  83.  
  84. wcop1:
  85.     jcxz    wcop3            ; keine dwords, dann carrytest2
  86.     rep     movsd            ; copy dwords
  87.  
  88.     jmp     short wcop3      ; carrytest2
  89.  
  90. .8086
  91.  
  92. wcop2:
  93.     rep     movsw            ; copy words
  94.     jmp     short wcop4      ; carrytest1
  95.  
  96. wcop3:
  97.     popf                     ; carry == ungerade words ?
  98.     jnc     wcop4            ; nein, dann nicht..
  99.     movsw                    ; ja, wird kopiert
  100.  
  101. wcop4:
  102.     popf                     ; carry == ungerade bytes ?
  103.     jnc     wcop5            ; nein, dann nicht..
  104.     movsb                    ; ja, wird kopiert1
  105.  
  106. wcop5:                       ; und tschüß...
  107.     pop     ds
  108.     pop     di
  109.     pop     si
  110.     pop     bp
  111.     ret
  112.  
  113. EndProc@    hswap,__CDECL__
  114.  
  115. ;* ******************************************************* *
  116. ;*  void meminit(void *buf,int anz,unsigned char wert)     *
  117. ;*                                                         *
  118. ;*  füllen einer Fläche mit Bytes                          *
  119. ;* ******************************************************* *
  120.  
  121. PubProc@    meminit,__CDECL__
  122.  
  123.     push    bp
  124.     mov     bp,sp
  125.     push    si
  126.     push    di
  127.  
  128. IF LDATA
  129. ; bei LARGE-Data-Modellen werden 4-Byte-Pointer übergeben
  130.     les     di,dword ptr [bp+4+PLUS]
  131.     mov     cx,word ptr [bp+8+PLUS]
  132.     mov     al,byte ptr [bp+10+PLUS]
  133. ELSE
  134. ;bei SMALL-Data Modellen sind beide Pointer im DS
  135.     push    ds
  136.     pop     es
  137.     mov     di,word ptr [bp+4+PLUS]
  138.     mov     cx,word ptr [bp+6+PLUS]
  139.     mov     al,byte ptr [bp+8+PLUS]
  140. ENDIF
  141.  
  142.     cld
  143.     jcxz    bfil6            ; nichts zu tun ??
  144.     mov     ah,al            ; Füllbyte wird Füllwort
  145.     shr     cx,1             ; Bytes /2 = worte
  146.     pushf                    ; ungerade bytes ? im carryflag
  147.  
  148. bfil1:
  149.     jcxz    bfil5            ; keine worte ? dann carrytest1
  150.     test    __cpu386,1       ; 386-er vorhanden ?
  151.     jz      bfil3            ; leider nicht
  152.  
  153. .386
  154.     push    ax               ; füllwort
  155.     shl     eax,16           ; nach oben schieben
  156.     pop     ax               ; und nach unten = füll-dword
  157.     shr     cx,1             ; worte /2 == dwords
  158.     pushf                    ; ungerade worte ? im carryflag
  159.  
  160. bfil2:
  161.     jcxz    bfil4            ; keine dwords, dann carrytest2
  162.     rep     stosd            ; copy dwords
  163.  
  164.     jmp     short bfil4      ; carrytest2
  165.  
  166. .8086
  167.  
  168. bfil3:
  169.     rep     stosw            ; copy words
  170.     jmp     short bfil5      ; carrytest1
  171.  
  172. bfil4:
  173.     popf                     ; carry == ungerade words ?
  174.     jnc     bfil5            ; nein, dann nicht..
  175.     stosw                    ; ja, wird kopiert
  176.  
  177. bfil5:
  178.     popf                     ; carry == ungerade bytes ?
  179.     jnc     bfil6            ; nein, dann nicht..
  180.     stosb                    ; ja, wird kopiert
  181.  
  182. bfil6:                       ; und Tschüß...
  183.     pop di
  184.     pop si
  185.     pop bp
  186.     ret
  187.  
  188. EndProc@    meminit,__CDECL__
  189.  
  190. CSegEnd@
  191.  
  192. end
  193. ;* ****************************************************** *
  194. ;*              Ende von 386MEM.ASM                       *
  195.  
  196.