Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <asm/linkage.h>
  2.  
  3. .code16
  4.  
  5. .section .text
  6.  
  7. GLOBAL(memcpy)
  8.     pushl   %esi
  9.     pushl   %edi
  10.  
  11.     movl    %eax, %edi
  12.     movl    %edx, %esi
  13.     pushl   %ecx
  14.     shrl    $2, %ecx
  15.     rep; movsl
  16.  
  17.     popl    %ecx
  18.     andl    $3, %ecx
  19.     rep; movsb
  20.  
  21.     popl    %edi
  22.     popl    %esi
  23.  
  24.     retl
  25. ENDPROC(memcpy)
  26.  
  27. GLOBAL(memset)
  28.     pushl   %edi
  29.  
  30.     movl    %eax, %edi
  31.     movzbl  %dl, %eax
  32.     imull   $0x01010101, %eax
  33.     pushl   %ecx
  34.     shrl    $2, %ecx
  35.     rep; stosl
  36.  
  37.     popl    %ecx
  38.     andl    $3, %ecx
  39.     rep; stosb
  40.  
  41.     popl    %edi
  42.  
  43.     retl
  44. ENDPROC(memset)
  45.  
  46. GLOBAL(memset16)
  47.     pushl   %edi
  48.  
  49.     movl    %eax, %edi
  50.     movzwl  %dx, %eax
  51.     imull   $0x00010001, %eax
  52.     pushl   %ecx
  53.     shrl    $2, %ecx
  54.     rep; stosl
  55.  
  56.     popl    %ecx
  57.     andl    $3, %ecx
  58.     rep; stosb
  59.  
  60.     popl    %edi
  61.  
  62.     retl
  63. ENDPROC(memset16)
  64.  
  65. GLOBAL(memset32)
  66.     pushl   %edi
  67.  
  68.     movl    %eax, %edi
  69.     movl    %edx, %eax
  70.     imull   $0x00000001, %eax
  71.     pushl   %ecx
  72.     shrl    $2, %ecx
  73.     rep; stosl
  74.  
  75.     popl    %ecx
  76.     andl    $3, %ecx
  77.     rep; stosb
  78.  
  79.     popl    %edi
  80.  
  81.     retl
  82. ENDPROC(memset32)
  83.  
  84. GLOBAL(memmove)
  85.     pushl   %esi
  86.     pushl   %edi
  87.  
  88.     movl    %edx, %esi
  89.     movl    %eax, %edi
  90.     pushl   %ecx
  91.  
  92.     cmpl    %edx, %eax
  93.     je      .memmove_done
  94.     jb      .memmove_fast
  95.  
  96. .memmove_slow:
  97.     std
  98.  
  99.     subl    $4, %ecx
  100.     addl    %ecx, %esi
  101.     addl    %ecx, %edi
  102.  
  103.     popl    %ecx
  104.     pushl   %ecx
  105.  
  106.     shrl    $2, %ecx
  107.     rep; movsl
  108.  
  109.     popl    %ecx
  110.     andl    $3, %ecx
  111.     rep; movsb
  112.  
  113.     cld
  114.  
  115.     jmp     .memmove_done
  116.  
  117. .memmove_fast:
  118.     shrl    $2, %ecx
  119.     rep; movsl
  120.  
  121.     popl    %ecx
  122.     andl    $3, %ecx
  123.     rep; movsb
  124.  
  125. .memmove_done:
  126.     popl    %edi
  127.     popl    %esi
  128.  
  129.     retl
  130. ENDPROC(memmove)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement