Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .text
- .type max_1_ind, @function
- .global max_1_ind
- #rdi -tab
- #rsi - n
- #rdx - even_count
- #rcx - neg-count
- max_1_ind:
- PUSH %rbx
- PUSH %rdx
- PUSH %rdi
- MOV $0, %r10 # even_count
- MOVB $0, (%rcx)
- MOV $0, %rbx #max 1 counter
- MOV %rsi, %r8
- loop:
- MOVQ (%rdi), %rax
- CMP $0, %rax
- JL negative
- afterNeg:
- MOVQ (%rdi), %rax
- XOR %rdx, %rdx
- XOR %r12, %r12
- MOV $2, %r12
- IDIV %r12d
- CMP $0, %rdx
- JE even
- afterEven:
- XOR %rax, %rax
- MOV (%rdi), %rax
- JMP count1
- afterCount:
- DEC %rsi
- ADD $8, %rdi
- CMP $0, %rsi
- JNE loop
- POP %rdi
- POP %rdx
- POP %rbx
- MOV %r11, %rax
- MOVQ %r10, (%rdx)
- RET
- negative:
- XOR %r12, %r12
- MOVQ (%rcx), %r12
- INC %r12
- MOVQ %r12, (%rcx)
- JMP afterNeg
- even:
- INC %r10
- JMP afterEven
- count1:
- XOR %r9, %r9
- XOR %r12, %r12
- MOV $0, %r9
- MOV $0, %r12 # how many 1
- countLoop:
- PUSH %rax
- AND $1, %rax
- CMP $0, %rax
- JE zero
- INC %r12
- zero:
- POP %rax
- SHR $1, %rax
- INC %r9
- CMP $64, %r9
- JNE countLoop
- CMP %r12, %rbx
- JG afterCount
- MOV %r12, %rbx
- MOVQ (%rdi), %r11
- JMP afterCount
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement