Advertisement
ArBa

dll_2

Jan 8th, 2020
2,369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .data
  2.  
  3. maxByteVal db  255
  4. wordCounter dq 8
  5.  
  6. .code
  7.  
  8.  
  9. DllMain PROC        ; ENTRY POINT FOR DLL
  10.     mov rax, 1
  11.     ret
  12. DllMain ENDP
  13.  
  14.  
  15. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  16. ;                                   INPUT DATA                                  ;
  17. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  18. ;   input - original pixel data array                                           ;
  19. ;   output - processed pixel data array                                         ;
  20. ;   parameter - number of colors to be left in image                            ;
  21. ;   size - length of pixel array                                                ;
  22. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  23.  
  24. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  25. ;                           INITIAL DATA LOCALIZATION                           ;
  26. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  27. ;   input = [RCX]                                                               ;
  28. ;   output = [RDX]                                                              ;
  29. ;   parameter = [R8]                                                            ;
  30. ;   size = [R9]                                                                 ;
  31. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  32.  
  33. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  34. ;                                   USED REGISTERS                              ;
  35. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  36. ; RSI - procedure iteration counter (esi)                                       ;
  37. ; RBX - matrix width as counter (ebx)                                           ;
  38. ; R9 - offset in assembler size (offset * matrix_width * size_of_float)         ;
  39. ; R8 - pointer to resultant matrix data                                         ;
  40. ; R12 - left array index                                                        ;
  41. ; R13 - right matrix index                                                      ;
  42. ; R14 - pointer to left matrix data                                             ;
  43. ; R15 - pointer to right matrix data                                            ;
  44. ; R10 - right matrix height as counter (R10d)                                   ;
  45. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  46.  
  47.  
  48.  
  49. posterise PROC
  50.  
  51. push    rbp                     ; save frame pointer
  52. mov     rbp, rsp                ; fix stack pointerrtffffffff
  53.  
  54. calculate_progVal:
  55.    ;calculate progging step value
  56.     mov     r10, rdx            ;save output to r10
  57.     movzx   rax, maxByteVal     ;set divisor to 255  
  58.     xor     rdx, rdx
  59.    
  60.     div     r8
  61.     mov     r11, rax            ;copy value to r9 and r10
  62.     mov     r12, rax
  63.     dec     r11
  64.     shr     r12, 1
  65.     xor     r13, r13
  66.  
  67. posterize:
  68.     cmp     r9, r13
  69.     je      done
  70.  
  71. fill_vector:
  72.     vpmovsxwd ymm0, xmmword ptr [rcx + r13]
  73.  
  74. transform:
  75.     movd xmm1, r12
  76.     vpbroadcastd ymm1, xmm1
  77.     vpaddd ymm0, ymm1, ymm0
  78.  
  79.     movd xmm1, r11
  80.     VPBROADCASTD YMM1, xmm1
  81.     vpand ymm2, ymm1, ymm0
  82.     vpsubd ymm0, ymm0, ymm2
  83.  
  84.     movd xmm1, r11
  85.     vpbroadcastd ymm1, xmm1
  86.     vpminsd ymm1, ymm0, ymm1
  87.  
  88. save_values:
  89.     vpackssdw ymm1, ymm1, ymm1
  90.     vpermq ymm1, ymm1, 12
  91.     movq qword ptr [r10 + r13], xmm1
  92.     add r13, wordCounter
  93.     jmp posterize
  94.  
  95.    
  96.  
  97.  
  98.  
  99. ; epilog. restore stack pointer
  100. done:
  101.     mov     rsp, rbp
  102.     pop     rbp
  103.     ret
  104.  
  105. posterise ENDP
  106.  
  107.  
  108.  
  109.  
  110. ;-------------------------------------------------------------------------
  111. end
  112. ;-------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement