Advertisement
Coriic

Untitled

Jun 25th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  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. MOV %rdi, %r9
  11. loop:
  12. CMP $0, %rsi
  13. JE afterLoop
  14. CMPB $0, (%rdi)
  15. JL afterHashing
  16. CMPB $63, (%rdi)
  17. JG afterHashing
  18. MOV (%rdi), %eax
  19. MOV occurences(, %eax, 4), %ebx
  20. INC %ebx
  21. MOV %ebx, occurences(, %eax, 4)
  22. afterHashing:
  23. ADD $4, %rdi
  24. DEC %rsi
  25. JMP loop
  26. afterLoop:
  27. MOV $63, %ecx
  28. XOR %rax, %rax
  29. XOR %rbx, %rbx
  30. MOV $0, %rbx
  31. loop2:
  32. XOR %r8, %r8
  33. MOV occurences(, %ecx, 4), %r8
  34. CMP %r8, %rbx
  35. JB swapMax
  36. afterSwap:
  37. SHL $1, %rax
  38. CMP $0, %r8
  39. JE noOccurences
  40. ADD $1, %rax
  41. afterModifing:
  42. DEC %ecx
  43. CMP $0, %ecx
  44. JGE loop2
  45. MOV %rbx, (%rdx)
  46. MOV %r9, %rdi
  47. RET
  48.  
  49. swapMax:
  50. MOV %r8, %rbx
  51. JMP afterSwap
  52.  
  53. noOccurences:
  54. ADD $0, %rax
  55. JMP afterModifing
  56.  
  57.  
  58. //---------------------------------------------------------------
  59. // Test program - grupa B
  60. //---------------------------------------------------------------
  61.  
  62. #include <stdio.h>
  63.  
  64. unsigned long long int check_tab(int *tab, int n, int *max);
  65.  
  66. int main() {
  67. int tab1[] = {-2,0,0,64,64};
  68. int tab2[] = {0,2,3,4,5,5,5, -1, 64, -1, -1, 5};
  69. int tab3[] = {0,-10, 66, 64, 64, 64};
  70. int tab4[] = {32,33,34,35,62,63};
  71. int tab5[] = {};
  72. unsigned long long int wyn;
  73. int max;
  74.  
  75. wyn = check_tab(tab1, 5, &max);
  76. printf("Result: %016llX, max: %d\n", wyn, max);
  77.  
  78. wyn = check_tab(tab2, 12, &max);
  79. printf("Result: %016llX, max: %d\n", wyn, max);
  80.  
  81. wyn = check_tab(tab3, 6, &max);
  82. printf("Result: %016llX, max: %d\n", wyn, max);
  83.  
  84. wyn = check_tab(tab4, 6, &max);
  85. printf("Result: %016llX, max: %d\n", wyn, max);
  86.  
  87. wyn = check_tab(tab5, 0, &max);
  88. printf("Result: %016llX, max: %d\n", wyn, max);
  89.  
  90. return 0;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement