emin_int11

Check If Two String Arrays are Equivalent ASM solution

Apr 14th, 2021
583
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. global _start
  2. section .text
  3. _start:
  4.     lea rdi, [str1]
  5.     call str_len
  6.     mov edx, eax
  7.     lea rdi, [str2]
  8.     call str_len
  9.     mov ebx, eax
  10.     cmp edx, ebx
  11.     jne _errlen
  12.     call _cmp_str
  13.     mov rbx, rax
  14.     call check_equal
  15.     jmp _exit
  16.  
  17. check_equal:
  18.     cmp rax, 1
  19.     je _CE2
  20. _CE1:
  21.     mov rsi, truemsg
  22.     mov rdx, 5
  23.     jmp _CE3
  24. _CE2: ; false state
  25.     mov rsi, falsemsg
  26.     mov rdx, 6
  27. _CE3:
  28.     mov rax, 1
  29.     mov rdi, 1
  30.     syscall
  31.     ret
  32.  
  33. str_len:
  34.     mov eax, 0
  35.     test rdi, rdi
  36.     jne _S2
  37. _S4:
  38.     add rax, 1
  39. _S2:
  40.     cmp byte [rdi + rax], 0
  41.     jne _S4
  42.     ret
  43.  
  44. _errlen:
  45.     mov rax, 1
  46.     mov rdi, 1
  47.     mov rsi, err
  48.     mov rdx, 21
  49.     syscall
  50.  
  51. _exit:
  52.     mov rax, 60
  53.     xor rdi, rdi
  54.     syscall
  55.     nop
  56.     nop
  57.     nop
  58. _cmp_str:
  59.     mov rcx, rdx
  60.     test rcx, rcx
  61.     lea rdi, [str1]
  62.     lea rsi, [str2]
  63. _L1:
  64.     movdqu  xmm0, [rdi]
  65.     movdqu  xmm1, [rsi]
  66.     mov    eax, ecx
  67.     mov    edx, ecx
  68.     pcmpestrm xmm0, xmm1, 0b11000 ; _SIDD_UBYTE_OPS | _SIDD_CMP_EQUAL_EACH | _SIDD_NEGATIVE_POLARITY | _SIDD_LEAST_SIGNIFICANT
  69.     setb   al
  70.     movzx  eax, al
  71.     jb _L2
  72.     cmp rcx, 16
  73.     ja _L3
  74. _L4:
  75.     ret
  76. _L3:
  77.     sub     rcx, 16
  78.     add     rdi, 16
  79.     add     rsi, 16
  80.     jmp _L1
  81. _L2:
  82.     nop
  83.     mov eax, 1
  84.     ret
  85.  
  86.  
  87. section .data
  88. err: db "length doesn't match", 10, 0
  89. truemsg: db "true", 10, 0
  90. falsemsg: db "false", 10, 0
  91.  
  92. align   16
  93. str1: db "abc", "d", "defg", 0
  94. str2: db "abcddefg", 0
  95.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×