Advertisement
Coriic

PT800

Jun 26th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .text
  2. .type fun, @function
  3. .global fun
  4.  
  5. #a - rdi
  6. #b - rsi
  7. #pcs - rdx
  8. #count - rcx
  9. fun:
  10.     PUSH %rbx
  11.     PUSH %rdx
  12.     XOR %rbx, %rbx
  13.     XOR %r9, %r9
  14.     XOR %r10, %r10
  15.     XOR %rax, %rax
  16.     MOV $1, %rbx # (i+1)
  17.     MOV $0, %r9 # how Many 1
  18.     CMP $1, %rsi # which bit
  19.     JE sum
  20.     CMP $2, %rsi
  21.     JE mul
  22.     JMP nothing
  23. loop:
  24.     PUSH %rdi
  25.     AND $1, %rdi
  26.     JMP count
  27. afterCount:
  28.     CMP $0, %rsi
  29.     JE afterOp
  30.     PUSH %rax
  31.     MOV %rdi, %rax
  32.     XOR %rdx, %rdx
  33.     MUL %rbx
  34.     MOV %rax, %r8
  35.     POP %rax
  36.     CMP $1, %rsi
  37.     JE sumOp
  38.     CMP $2, %rsi
  39.     JE mulOp
  40. afterOp:
  41.     POP %rdi
  42.     INC %rbx
  43.     SHR $1, %rdi
  44.     CMP $64, %rbx
  45.     JNE loop
  46. afterLoop:
  47.     POP %rdx
  48.     POP %rbx
  49.     MOVL %r9d, (%rcx)
  50.     MOVL %r10d, (%rdx)
  51.     RET
  52.  
  53. sum:
  54.     MOV $0, %rax #starting value
  55.     JMP loop
  56.  
  57. mul:
  58.     MOV $1, %rax #starting value
  59.     JMP loop
  60.  
  61. nothing:
  62.     MOV $0, %rax
  63.     JMP loop
  64.  
  65. sumOp:
  66.     ADD %r8, %rax #xi in rax
  67.     JMP afterOp
  68.  
  69. mulOp:
  70.     CMP $0, %r8
  71.     JE afterOp
  72.     XOR %rdx, %rdx
  73.     MUL %r8 #xi in rax
  74.     JMP afterOp
  75.  
  76. count:
  77.     CMP $0, %rdi
  78.     JE afterCount
  79.     INC %r9
  80.     MOV %rbx, %r10
  81.     JMP afterCount
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement