Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. .data
  3.     dqwColorArray db 16 dup (?) ;Array which will fill xmm register with bytest from color to remove.
  4. .code
  5. processPictureAssembler PROC
  6.         ;Move data aqquired from C# function call to general purpouse registers.
  7.         MOV r9, rcx ;Photo pixels in bytes.
  8.         MOV r10, rdx ;Removable color.
  9.         MOV r11, r8 ;Amount of bytes (in array stored in r9 register).
  10.  
  11.         XOR rcx, rcx ;Clear counter.
  12.         MOV rax, OFFSET dqwColorArray ;Move array address ro RAX
  13.  
  14. ;Fill dqwColorArray with color to remove.
  15. ;Sequence: A R G B
  16. xmmFilerLoop:
  17.         ;Alpha is hardcoded to 255 and in not taken from GUI
  18.         XOR r12,r12
  19.         NOT r12
  20.         MOV [rax], r12b
  21.        
  22.         ;R value is read from GUI input and saved to array
  23.         ADD rax,TYPE dqwColorArray
  24.         MOV r12b, [r10]
  25.         MOV [rax], r12b
  26.        
  27.         ;G value is read from GUI input and saved to array
  28.         ADD rax,TYPE dqwColorArray
  29.         MOV r12b, [r10+1]
  30.         MOV [rax], r12b
  31.  
  32.         ;B value is read from GUI input and saved to array
  33.         ADD rax,TYPE dqwColorArray
  34.         MOV r12b, [r10+2]
  35.         MOV [rax], r12b
  36.  
  37.         ;Move further in dqwColorArray and increment counter by 4.
  38.         ADD rax,TYPE dqwColorArray
  39.         ADD rcx, 4
  40.  
  41.         ;Chcek if whole array was filled.
  42.         CMP rcx, 16s
  43.         JNE xmmFilerLoop
  44.        
  45.         ;Use array to fill xmm0 register
  46.         MOV rax, OFFSET dqwColorArray
  47.         MOVDQU xmm0, [rax] ;Move double quad word unalligned
  48.  
  49. ;Procces picture data
  50.  
  51.         ;Picture size smaller ten 4 px (16 bytes)
  52.         CMP r11, 16
  53.         JB lessThen16 ;If smaller jump
  54.        
  55.         MOV rax, r9 ;Push pixelArray (in bytes) to RAX
  56. sseLoop:       
  57.         MOVDQU xmm1, [rax] ;Move 16 bytes (4 pixels) from PixelArray to xmm
  58.         PCMPEQD xmm0, xmm1 ;Check if quadwords (pixels) are equals if so change in xmm0 pixel bits to 1
  59.         PCMPEQD xmm2, xmm2 ;Set all xmm2 bits to 1
  60.         PXOR xmm0,xmm2 ;PXOR + previous instruction makes bitwise negation of xmm0 bits
  61.         PAND xmm1, xmm0 ;Clear appropriate bits in xmm1
  62.         MOVDQU [rax], xmm1 ;Save changed pixels back to array
  63.  
  64.         ADD rax, 16 ;Mov to next bytes in pixelArray
  65.        
  66.         SUB r11, 16 ;Reduce unprocessed bytes amount by 16
  67.         CMP r11, 0 ;Check if bytes amount is enough to fill xmm register.
  68.         JLE restPixelLoop
  69.        
  70.        
  71.         ;Refil xmm0
  72.         MOV r13, OFFSET dqwColorArray
  73.         MOVDQU xmm0, [r13]
  74.         JMP sseLoop
  75. ;Responsible for rest of pixels (less than 16 left)
  76. restPixelLoop:
  77.         ;Else proces leftovers
  78.         add r11, 16
  79.  
  80.    
  81. lessThen16:
  82.         ;If all processed exit
  83.         CMP r11, 0
  84.         JZ exit
  85.  
  86.         ;Check A
  87.         mov r12b, 255
  88.         mov r13b, [rax]
  89.         cmp [rax],r12b
  90.         jne bypassPixel
  91.         ;Check R
  92.         mov r12b, [r10]
  93.         mov r13b, [rax + 1]
  94.         cmp [rax + 1], r12b
  95.         jne bypassPixel
  96.         ;Check G
  97.         mov r12b, [r10 + 1]
  98.         mov r13b, [rax + 2]
  99.         cmp [rax + 2], r12b
  100.         jne bypassPixel
  101.         ;Check B
  102.         mov r12b, [r10 + 2]
  103.         mov r13b, [rax + 3]
  104.         cmp [rax + 3], r12b
  105.         jne bypassPixel
  106.        
  107.         ;Clear pixel
  108.         xor r14,r14
  109.         mov [rax],r14b
  110.         mov [rax+1],r14b
  111.         mov [rax+2],r14b
  112.         mov [rax+3],r14b
  113.         mov r13b,[rax]
  114.         mov r13b,[rax+1]
  115.         mov r13b,[rax+2]
  116.         mov r13b,[rax+3]
  117. bypassPixel:
  118.         ;If some byte of pixel is not equal to removable color than go to next pixel.
  119.         sub r11, 4
  120.        
  121.         ;CMP r11, 0
  122.         ;JZ exit   
  123.         add rax, 4
  124.         jmp lessThen16
  125. exit:
  126. mov rax,0
  127. ret
  128.  
  129. processPictureAssembler ENDP
  130.  
  131. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement