Advertisement
Coriic

Untitled

Jun 25th, 2017
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .text
  2. .type max_1_ind, @function
  3. .global max_1_ind
  4.  
  5. #rdi  -tab
  6. #rsi - n
  7. #rdx - even_count
  8. #rcx - neg-count
  9. max_1_ind:
  10.     PUSH %rbx
  11.     PUSH %rdx
  12.     PUSH %rdi
  13.     MOV $0, %r10 # even_count
  14.     MOVB $0, (%rcx)
  15.     MOV $0, %rbx #max 1 counter
  16.     MOV %rsi, %r8
  17. loop:
  18.     MOVQ (%rdi), %rax
  19.     CMP $0, %rax
  20.     JL negative
  21. afterNeg:
  22.     MOVQ (%rdi), %rax
  23.     XOR %rdx, %rdx
  24.     XOR %r12, %r12
  25.     MOV $2, %r12
  26.     IDIV %r12d
  27.     CMP $0, %rdx
  28.     JE even
  29. afterEven:
  30.     XOR %rax, %rax
  31.     MOV (%rdi), %rax
  32.     JMP count1
  33. afterCount:
  34.     DEC %rsi
  35.     ADD $8, %rdi
  36.     CMP $0, %rsi
  37.     JNE loop
  38.     POP %rdi
  39.     POP %rdx
  40.     POP %rbx
  41.     MOV %r11, %rax
  42.     MOVQ %r10, (%rdx)
  43.     RET
  44.  
  45. negative:
  46.     XOR %r12, %r12
  47.     MOVQ (%rcx), %r12
  48.     INC %r12
  49.     MOVQ %r12, (%rcx)
  50.     JMP afterNeg
  51.  
  52. even:
  53.     INC %r10
  54.     JMP afterEven
  55.  
  56. count1:
  57.     XOR %r9, %r9
  58.     XOR %r12, %r12
  59.     MOV $0, %r9
  60.     MOV $0, %r12 # how many 1
  61. countLoop:
  62.     PUSH %rax
  63.     AND $1, %rax
  64.     CMP $0, %rax
  65.     JE zero
  66.     INC %r12
  67. zero:
  68.     POP %rax
  69.     SHR $1, %rax
  70.     INC %r9
  71.     CMP $64, %r9
  72.     JNE countLoop
  73.     CMP %r12, %rbx
  74.     JG afterCount
  75.     MOV %r12, %rbx
  76.     MOVQ (%rdi), %r11
  77.     JMP afterCount
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement