Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .data
- occurences:
- .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
- .text
- .type check_tab, @function
- .global check_tab
- #tab->n->max
- check_tab:
- MOV %rdi, %r9
- loop:
- CMP $0, %rsi
- JE afterLoop
- CMPB $0, (%rdi)
- JL afterHashing
- CMPB $63, (%rdi)
- JG afterHashing
- MOV (%rdi), %eax
- MOV occurences(, %eax, 4), %ebx
- INC %ebx
- MOV %ebx, occurences(, %eax, 4)
- afterHashing:
- ADD $4, %rdi
- DEC %rsi
- JMP loop
- afterLoop:
- MOV $63, %ecx
- XOR %rax, %rax
- XOR %rbx, %rbx
- MOV $0, %rbx
- loop2:
- XOR %r8, %r8
- MOV occurences(, %ecx, 4), %r8
- CMP %r8, %rbx
- JB swapMax
- afterSwap:
- SHL $1, %rax
- CMP $0, %r8
- JE noOccurences
- ADD $1, %rax
- afterModifing:
- DEC %ecx
- CMP $0, %ecx
- JGE loop2
- MOV %rbx, (%rdx)
- MOV %r9, %rdi
- RET
- swapMax:
- MOV %r8, %rbx
- JMP afterSwap
- noOccurences:
- ADD $0, %rax
- JMP afterModifing
- //---------------------------------------------------------------
- // Test program - grupa B
- //---------------------------------------------------------------
- #include <stdio.h>
- unsigned long long int check_tab(int *tab, int n, int *max);
- int main() {
- int tab1[] = {-2,0,0,64,64};
- int tab2[] = {0,2,3,4,5,5,5, -1, 64, -1, -1, 5};
- int tab3[] = {0,-10, 66, 64, 64, 64};
- int tab4[] = {32,33,34,35,62,63};
- int tab5[] = {};
- unsigned long long int wyn;
- int max;
- wyn = check_tab(tab1, 5, &max);
- printf("Result: %016llX, max: %d\n", wyn, max);
- wyn = check_tab(tab2, 12, &max);
- printf("Result: %016llX, max: %d\n", wyn, max);
- wyn = check_tab(tab3, 6, &max);
- printf("Result: %016llX, max: %d\n", wyn, max);
- wyn = check_tab(tab4, 6, &max);
- printf("Result: %016llX, max: %d\n", wyn, max);
- wyn = check_tab(tab5, 0, &max);
- printf("Result: %016llX, max: %d\n", wyn, max);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement