Guest User

Untitled

a guest
Jan 17th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. -- Prologue.
  2. | push rbp
  3. | mov rbp, rsp
  4. -- Accumulative sum (16-bit).
  5. | xor r9, r9 -- Clear out r9. Stores accumulated sum.
  6. | mov rcx, 0 -- Set index to 0.
  7. | 1:
  8. | cmp rcx, rsi -- Rsi stores size arg. Compare index to size.
  9. | jg >2 -- Go to branch '2' if equals.
  10. | mov ah, [rdi + rcx] -- Read 16-bit of data and swapping byte order.
  11. | mov al, [rdi + rcx+1]
  12. | add r9, rax -- Sum and accumulate into r9.
  13. | add rcx, 2 -- Increase index by 2.
  14. | jmp <1 -- Go to beginning of loop.
  15. | 2:
  16. | mov rax, r9 -- Save accumulated sum in rax.
  17. -- Sum carry until done.
  18. | 4:
  19. | shr r9, 16 -- Right-shift r9 16-bit to obtain value of carry.
  20. | cmp r9, 0 -- Check whether there's carry.
  21. | jz >5 -- In case not, go to '4'.
  22. | and rax, 0xffff -- Clear out higher part of rax.
  23. | add rax, r9 -- Sum carry to rax.
  24. | mov r9, rax -- Assign rax to r9 to check if there's carry again.
  25. | jmp <4 -- Go to beggining of loop.
  26. -- One-complement.
  27. | 5:
  28. | not rax -- One-complement of rax.
  29. | and rax, 0xffff -- Clear out higher part of rax.
  30. -- Epilogue.
  31. | mov rsp, rbp
  32. | pop rbp
  33. -- Return.
  34. | ret
Add Comment
Please, Sign In to add comment