Advertisement
Guest User

somatorio

a guest
Oct 22nd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. .section .data
  2. .global A
  3. .global B
  4. .global j
  5.  
  6. .section .text
  7. .global swapBytes #Declared function
  8.  
  9.  
  10. ###################################
  11. #Prologue
  12. ###################################
  13. pushl %ebp #save previous stack frame pointer
  14. movl %esp, %ebp #the stack frame pointer for sum function
  15.  
  16. ###################################
  17. #Save registers
  18. ###################################
  19. pushl %ebx
  20. pushl %esi
  21. pushl %edi
  22.  
  23. ###################################
  24. # Body of the function
  25. # here we implement our function...
  26. ###################################
  27.  
  28. #Cleans 32bit registers
  29. movl $0, %eax
  30. movl $0, %ebx
  31. movl $0, %ecx
  32. movl $0, %edx
  33. movl $0, %esi
  34. movl $0, %edi
  35.  
  36. #Places variables values to registers
  37. movl A, %eax #Places A value to eax register
  38. movl B, %ebx #Places B value to ebp register
  39.  
  40. #Defines limit
  41. movl j, %ecx #Places j in ecx register
  42. movl $1, %edx #Places 1 in edx register
  43.  
  44. jmp loop #Jumps loop
  45.  
  46. loop:
  47. imull %edx, %eax #multiplies edx value to eax value (A)
  48. idiv %ebx #divids eax by ebx (ebx is divisor)
  49. addl %eax, %esi #adds eax value to esi (empty in the beginning), palcing the result in esi
  50. movl A, %eax
  51.  
  52. #Compare to limit
  53. cmpl %ecx, %ebx #Compares registers values (ebx - ecx)
  54. jge endLoop #Jumps loop if greater or equal
  55.  
  56.  
  57. #Iterating i++
  58. incl %edx #adds 1 to edx value
  59.  
  60. jmp loop #Jumps loop
  61.  
  62.  
  63. endLoop:
  64. movl $0, %eax #Cleans eax register
  65. movl %esi, %eax #Moves esi content to eax
  66.  
  67. ###################################
  68. #Restore registers
  69. ###################################
  70. popl %edi
  71. popl %esi
  72. popl %ebx
  73.  
  74. ###################################
  75. #Epilogue
  76. ###################################
  77. movl %ebp, %esp #Restore the previous stack pointer ("clear" the stack)
  78. popl %ebp #Restore the previous stack frame pointer
  79.  
  80. ret #Return from the function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement