Coriic

Untitled

Jun 25th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .data
  2.     occurences:
  3.     .long 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  4. .text
  5. .type check_tab, @function
  6. .global check_tab
  7.  
  8. #tab->n->max
  9. check_tab:
  10.     PUSH %rbx
  11.     XOR %rbx, %rbx
  12.     XOR %rax, %rax
  13.     XOR %r8, %r8
  14.     XOR %r9, %r9
  15.     XOR %rcx, %rcx
  16.     MOV $0, %ecx
  17. clear:
  18.     MOVL $0, occurences(, %ecx, 4)
  19.     INC %ecx
  20.     CMP $64, %ecx
  21.     JNE clear
  22.     XOR %ecx, %ecx
  23.     MOV %rdi, %r9
  24. loop:
  25.     CMP $0, %rsi
  26.     JE afterLoop
  27.     CMPB $0, (%rdi)
  28.     JL afterHashing
  29.     CMPB $63, (%rdi)
  30.     JG afterHashing
  31.     MOV (%rdi), %eax
  32.     MOV occurences(, %eax, 4), %ebx
  33.     INC %ebx
  34.     MOV %ebx, occurences(, %eax, 4)
  35. afterHashing:
  36.     ADD $4, %rdi
  37.     DEC %rsi
  38.     JMP loop
  39.  
  40.  
  41.  
  42. afterLoop:
  43.     MOV $63, %ecx
  44.     XOR %rax, %rax
  45.     XOR %rbx, %rbx
  46.     MOV $0, %r8
  47. loop2:
  48.     XOR %rbx, %rbx
  49.     MOVL occurences(, %ecx, 4), %ebx
  50.     CMP %r8, %rbx
  51.     JG swapMax
  52. afterSwap:
  53.     SHL $1, %rax
  54.     CMP $0, %ebx
  55.     JE afterModifing
  56.     ADD $1, %rax
  57. afterModifing:
  58.     DEC %ecx
  59.     CMP $0,%ecx
  60.     JGE loop2
  61.     MOV %r8,%rbx
  62.     MOVL %ebx, (%rdx)
  63.     MOV %r9, %rdi
  64.     POP %rbx
  65.     RET
  66.  
  67. swapMax:
  68.     MOV %rbx, %r8
  69.     JMP afterSwap
Add Comment
Please, Sign In to add comment