Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2014
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.47 KB | None | 0 0
  1. .file "prime.c"
  2. .text
  3. .globl square
  4. .type square, @function
  5. square:
  6. pushl %esp ;should be pushl %ebp
  7. movl %esp, %ebp ;setup
  8. movl 12(%ebp), %eax ;copies value from mem location whose address is +12 away from content of ebp into eax
  9. imull 8(%ebp), %eax ;multiplies the content of mem location whose address is +8 away from content of ebp by eax,
  10. ;and stores it in eax
  11. popl %ebp ;finish
  12. ret
  13. .size square, .-square
  14. .globl isPrime
  15. .type isPrime, @function
  16. isPrime:
  17. pushl %ebp ;setup
  18. movl %esp, %ebp ;setup
  19. subl $36, %esp ;subtracts the 36 from content in esp and stores it in esp
  20. movl 8(%ebp), %eax ;copies the content of mem location whose address is +8 away from content of ebp to eax
  21. andl $1, %eax ;compares content of eax with 1
  22. testl %eax, %eax ;**Possible error** eax&eax; ZF (zero flag) set when eax&eax == 0, SF (sign flag) when < 0
  23. jmp .L4 ;jump to .L4
  24. cmpl $2, 8(%ebp) ;compares the content of mem location whose address is +8 away from ebp to 2
  25. jne .L6 ;if the numbers are not equal, jump to .L6
  26. .L4:
  27. movl 8(%ebp), %eax ;copies the content of mem location whose address is +8 away from ebp into eax
  28. movl %eax, -28(%ebp) ;copies the content of eax to the mem location -32 away from ebp
  29. movl $1431655766, -32(%ebp) ;I have a feeling this is wrong, copies 1431655766 to the mem location -32 away from ebp
  30. movl -32(%ebp), %eax ;copies the content of mem location whose address is -32 away from ebp to eax
  31. imull -28(%ebp) ;I also feel this is wrong, imull requires 2 arguments no?
  32. movl %edx, %ecx ;copies the contents of edx to ecx
  33. movl -28(%ebp), %eax ;copies the content of mem location -28 away from ebp to eax
  34. sarl $31, %eax ;shift the content of eax to the right 31 bits and stores result in eax
  35. movl %ecx, %edx ;copies content of ecx to edx
  36. subl %eax, %edx ;subtracts eax from edx and stores the result in edx
  37. movl %edx, -24(%ebp) ;copies the contents of edx to the mem location whose address is -24 away from ebp
  38. movl -24(%ebp), %eax ;copies the content of mem location whose address is -24 away from ebp to eax
  39. addl %eax, %eax ;adds eax to eax and stores it in eax
  40. addl -24(%ebp), %eax ;adds the contents of the mem location whose address is -24 away from ebp to eax and the result is stored in eax
  41. movl -28(%ebp), %ecx ;adds the contents of the mem location whose address is -28 away from ebp to eax and the result is stored in eax
  42. subl %eax, %ecx ;subtracts content of eax from ecx and stores the result in ecx
  43. movl %ecx, -24(%ebp) ;copies the content of ecx to the mem location whose address is -24 away from ebp
  44. cmpl $0, -24(%ebp) ;compares the content of the mem location whose address is -24 away from ebp to 0
  45. jne .L7 ;if it is not 0, jump to .L7
  46. cmpl $3, 8(%ebp) ;compares the content of the mem location whose address is 8 away from ebp to 3
  47. jne .L6 ;if not 3, jump to .L6 (?) Not 3/not zero?
  48. .L7:
  49. cmpl $1, 8(%ebp) ;compares the content of the mem location whose address is 8 away from ebp to 1
  50. jg .L9 ;if greater than 1, jump to .L9
  51. .L6:
  52. movl $0, -20(%ebp) ;copies 0 to the mem location whose address is -20 from ebp
  53. jmp .L10 ;jumps to .L10
  54. .L9:
  55. movl $1, -8(%ebp) ;copies 1 to the mem location whose address is -8 away from ebp
  56. jmp .L11 ;jump to .L11
  57. .L12:
  58. movl -8(%ebp), %edx ;copies the content of the mem location whose address is -8 from ebp to edx
  59. movl %edx, %eax ;copies content of edx to eax
  60. addl %eax, %eax ;adds eax to eax and stores in eax
  61. addl %edx, %eax ;adds edx to eax and stores in eax
  62. addl %eax, %eax ;adds eax to eax and stores in eax
  63. movl %eax, -4(%ebp) ;copies content of eax to mem location whose address is -4 away from ebp
  64. movl -4(%ebp), %eax ;copies the content of the mem location whose address is -4 from ebp to eax (?)
  65. subl $1, %eax ;subracts 1 from eax and stores result in eax
  66. movl 8(%ebp), %edx ;copies the content of the mem location whose address is 8 away from ebp to edx
  67. movl %eax, %ecx ;copies eax to ecx
  68. movl %edx, %eax ;copies edx to eax
  69. sarl $31, %edx ;shifts edx to the right 31 bits and stores result in edx
  70. idivl %ecx ;?? divides the contents of edx:eax by contents of ecx, quotient into eax and remainder in edx
  71. movl %edx, %eax ;copies edx to eax
  72. testl %eax, %eax ;? eax&eax; ZF set when eax&eax == 0, SF when < 0
  73. jne .L13 ;? ~ZF (not equal/not zero) jump to .L13
  74. movl -4(%ebp), %eax ;copies contents of mem location whose address is -4 away from ebp to eax
  75. subl $1, %eax ;subtracts 1 from eax and stores result in eax
  76. cmpl 8(%ebp), %eax ;compares the content of the mem location whose address is 8 away from ebp to eax; eax(a)-8(ebp)(b); ZF set if a==b, SF set if <0, OF set if two's complement overflow
  77. je .L13 ;if zero, jump to .L13
  78. movl $0, -20(%ebp) ;copies 0 to the mem location whose address is -20 from ebp
  79. jmp .L10 ;jump to .L10
  80. .L13:
  81. movl -4(%ebp), %eax ;copies the contents of mem location whose address is -4 from ebp to eax
  82. addl $1, %eax ;adds 1 to eax;
  83. movl 8(%ebp), %edx ;copies the content of the mem location whose address is 8 away from ebp to edx
  84. movl %eax, %ecx ;copies eax to ecx
  85. movl %edx, %eax ;copies edx to eax
  86. sarl $31, %edx ;shifts content of edx right 31 bits and stores in edx
  87. idivl %ecx ;divides contents of edx:eax by by contents of ecx
  88. movl %edx, %eax ;copies edx to eax
  89. testl %eax, %eax ;?eax&eax; ZF set when eax&eax == 0, SF when < 0
  90. jne .L16 ;~ZF not equal/not zero jump to .L16
  91. movl -4(%ebp), %eax ;copies contents of mem location whose address is -4 from ebp to eax
  92. addl $1, %eax ;adds 1 to eax
  93. cmpl 8(%ebp), %eax ;compares the contents of the mem location whose address is 8 from ebp to eax
  94. je .L16 ;if zero, jump to .L16
  95. movl $0, -20(%ebp) ;copies 0 to the mem location whose address is -20 from ebp
  96. jmp .L10 ;jump to .L10
  97. .L16:
  98. addl $1, -8(%ebp) ;adds 1 to the mem location whose address is -8 from ebp
  99. .L11:
  100. movl -8(%ebp), %edx ;copies the contents on the mem location whose address is -8 from ebp to edx
  101. movl %edx, %eax ;edx to eax (eax = edx)
  102. addl %eax, %eax ;adds eax to eax, stores in eax (eax =+ eax)
  103. addl %edx, %eax ;adds edx to eax, stores in eax
  104. addl %eax, %eax ;adds eax to eax, stores in eax
  105. subl $7, %eax ;subtracts 7 from eax
  106. movl %eax, (%esp) ;copies eax to the mem location esp
  107. call square ;calls square function
  108. cmpl 8(%ebp), %eax ;compares the contents of mem location whose address is 8 away from ebp to eax
  109. jl .L12 ;if less than, jump to .L12
  110. movl $1, -20(%ebp) ;copies 1 to mem location whose address is -20 from ebp
  111. .L10:
  112. movl -20(%ebp), %eax ;copies content of mem location whose address is -20 from ebp to eax
  113. leave ;finish
  114. ret ;finish
  115. .size isPrime, .-isPrime
  116. .section .rodata
  117. .LC0:
  118. .string "Prime %d is %d\n"
  119. .text
  120. .globl main
  121. .type main, @function
  122. main:
  123. leal 4(%esp), %ecx ;4+esp stored in ecx (ecx = 4+esp)
  124. andl $-16, %esp ;? esp = esp&-16
  125. pushl -4(%ecx) ;puts the contents of the mem location whose address is -4 from ecx onto the stack
  126. pushl %ebp ;puts ebp on the stack
  127. movl %ebp, %esp ;esp = ebp
  128. pushl %ecx ;puts ecx on the stack
  129. subl $36, %esp ;subtracts 36 from esp, stores in esp
  130. movl 4(%ecx), %eax ;copies content of mem location whose address is 4 away from ecx to eax
  131. addl $0, %eax ;?? adds 0 to eax
  132. movl (%eax), %eax ;?? copies the content of mem location of eax to eax
  133. movl %eax, (%esp) ;copies eax to the mem location of esp
  134. call atoi ;calls atoi (converts string to int)
  135. movl %eax, -16(%ebp) ;copies eax to the mem location whose address is -16 from ebp
  136. movl $0, -12(%ebp) ;copies 0 into the mem location whose address is -12 from ebp
  137. movl $1, -8(%ebp) ;copies 1 into the mem location whose address is -8 from ebp
  138. jmp .L27 ;jump to .L27
  139. .L23:
  140. addl $1, -8(%ebp) ;adds 1 to the mem location whose address is -8 from ebp, stores in mem location
  141. movl -8(%ebp), %eax ;copies the content of the mem location whose address is -8 from ebp to eax
  142. movl %eax, (%esp) ;copies eax to mem location of esp
  143. call isPrime ;call isPrime function
  144. testl %eax, %eax ;eax = eax&eax
  145. je .L22 ;if equal/zero jumo to .L22
  146. addl $1, -12(%ebp) ;? add 1 to the mem location whose address is -12 from ebp, store in mem location
  147. .L22:
  148. .L27:
  149. movl -12(%ebp), %eax ;copies the content of mem location whose address is -12 from ebp to eax
  150. cmpl -16(%ebp), %eax ;compares content of mem location whose address is -16 from ebp to eax
  151. jl .L23 ;if <, then jump to .L23
  152. movl -8(%ebp), %eax ;copies content of mem location whose address is -8 from ebp to eax
  153. movl %eax, 8(%esp) ;copies eax to mem location whose address is 8 from esp
  154. movl -16(%ebp), %eax ;copies content of mem location whose address is -16 from ebp to eax
  155. movl %eax, 4(%esp) ;copies eax to mem location whose address is 4 from esp
  156. movl $.LC0, (%esp) ;copies .LC0 to mem location of esp
  157. call printf ;print function
  158. movl $0, %eax ;copies 0 to eax
  159. addl $36, %esp ;adds 36 to esp, stored in esp
  160. popl %ecx ;finish
  161. popl %ebp ;finish
  162. leal -4(%ecx), %esp ;**possible error** esp = -4+ecx
  163. ret ;finish
  164. .size main, .-main
  165. .ident "GCC: (GNU) 4.1.2 20080704 (Red Hat 4.1.2-51)"
  166. .section .note.GNU-stack,"",@progbits
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement