Advertisement
Coriic

Untitled

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