Guest User

Untitled

a guest
Aug 14th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.16 KB | None | 0 0
  1. wrong return in asm function (x86)
  2. .globl function
  3.  
  4. .data
  5. var1: .long 0
  6. var2: .long 0
  7.  
  8. .text
  9. function:
  10. movl 4(%esp), %eax
  11. movl 8(%esp), %ebx
  12.  
  13. cmp %eax, %ebx
  14. jg cond1 /*greater, if a < b */
  15. jl cond2 /*lower, if a > b */
  16.  
  17. movl var2, %eax
  18.  
  19. ret
  20.  
  21. cond1:
  22. movl %eax, var1 /*var1 = a */
  23. movl %ebx, var2 /*var2 = b */
  24. ret
  25.  
  26.  
  27. cond2:
  28. movl %eax, var2 /*var2 = a*/
  29. movl %ebx, var1 /*var1 = b */
  30. ret
  31.  
  32. function:
  33. movl 4(%esp), %eax
  34. movl 8(%esp), %ebx
  35.  
  36. cmp %eax, %ebx
  37. jg cond1 /*greater, if a < b */
  38. jl cond2 /*lower, if a > b */
  39. next:
  40. movl var2, %eax
  41. ret
  42.  
  43. cond1:
  44. movl %eax, var1 /*var1 = a */
  45. movl %ebx, var2 /*var2 = b */
  46. jmp next
  47.  
  48.  
  49.  
  50. cond2:
  51. movl %eax, var2 /*var2 = a*/
  52. movl %ebx, var1 /*var1 = b */
  53. jmp next
  54.  
  55. if (condition) cond1();
  56.  
  57. if (condition) goto cond1;
  58.  
  59. ----caller----.
  60. |
  61. v
  62.  
  63. function:
  64. movl 4(%esp), %eax
  65. movl 8(%esp), %ebx
  66.  
  67. cmp %eax, %ebx
  68. jg cond1 /*greater, if a < b */
  69.  
  70. |
  71. branch
  72. |
  73. v
  74.  
  75. cond1:
  76. movl %eax, var1 /*var1 = a */
  77. movl %ebx, var2 /*var2 = b */
  78. ret
  79.  
  80. |
  81. return to |
  82. <---caller----'
  83.  
  84. ----caller----.
  85. |
  86. v
  87.  
  88. function:
  89. movl 4(%esp), %eax
  90. movl 8(%esp), %ebx
  91.  
  92. cmp %eax, %ebx
  93. jg cond1 /*greater, if a < b */
  94. jl cond2 /*lower, if a > b */
  95.  
  96. |
  97. branch
  98. |
  99. v
  100.  
  101. cond2:
  102. movl %eax, var2 /*var2 = a*/
  103. movl %ebx, var1 /*var1 = b */
  104. ret
  105.  
  106. |
  107. return to |
  108. <---caller----'
  109.  
  110. ----caller----.
  111. |
  112. v
  113.  
  114. function:
  115. movl 4(%esp), %eax
  116. movl 8(%esp), %ebx
  117.  
  118. cmp %eax, %ebx
  119. jg cond1 /*greater, if a < b */
  120. jl cond2 /*lower, if a > b */
  121.  
  122. movl var2, %eax
  123.  
  124. ret
  125.  
  126. |
  127. return to |
  128. <---caller----'
  129.  
  130. function:
  131. movl 4(%esp), %eax /* EAX = a */
  132. cmpl 8(%esp), %eax /* Is a >= b? */
  133. jge done /* yes, return a (already in EAX) */
  134. movl 8(%esp), %eax /* no, return b */
  135. done:
  136. ret
Add Comment
Please, Sign In to add comment