Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- wrong return in asm function (x86)
- .globl function
- .data
- var1: .long 0
- var2: .long 0
- .text
- function:
- movl 4(%esp), %eax
- movl 8(%esp), %ebx
- cmp %eax, %ebx
- jg cond1 /*greater, if a < b */
- jl cond2 /*lower, if a > b */
- movl var2, %eax
- ret
- cond1:
- movl %eax, var1 /*var1 = a */
- movl %ebx, var2 /*var2 = b */
- ret
- cond2:
- movl %eax, var2 /*var2 = a*/
- movl %ebx, var1 /*var1 = b */
- ret
- function:
- movl 4(%esp), %eax
- movl 8(%esp), %ebx
- cmp %eax, %ebx
- jg cond1 /*greater, if a < b */
- jl cond2 /*lower, if a > b */
- next:
- movl var2, %eax
- ret
- cond1:
- movl %eax, var1 /*var1 = a */
- movl %ebx, var2 /*var2 = b */
- jmp next
- cond2:
- movl %eax, var2 /*var2 = a*/
- movl %ebx, var1 /*var1 = b */
- jmp next
- if (condition) cond1();
- if (condition) goto cond1;
- ----caller----.
- |
- v
- function:
- movl 4(%esp), %eax
- movl 8(%esp), %ebx
- cmp %eax, %ebx
- jg cond1 /*greater, if a < b */
- |
- branch
- |
- v
- cond1:
- movl %eax, var1 /*var1 = a */
- movl %ebx, var2 /*var2 = b */
- ret
- |
- return to |
- <---caller----'
- ----caller----.
- |
- v
- function:
- movl 4(%esp), %eax
- movl 8(%esp), %ebx
- cmp %eax, %ebx
- jg cond1 /*greater, if a < b */
- jl cond2 /*lower, if a > b */
- |
- branch
- |
- v
- cond2:
- movl %eax, var2 /*var2 = a*/
- movl %ebx, var1 /*var1 = b */
- ret
- |
- return to |
- <---caller----'
- ----caller----.
- |
- v
- function:
- movl 4(%esp), %eax
- movl 8(%esp), %ebx
- cmp %eax, %ebx
- jg cond1 /*greater, if a < b */
- jl cond2 /*lower, if a > b */
- movl var2, %eax
- ret
- |
- return to |
- <---caller----'
- function:
- movl 4(%esp), %eax /* EAX = a */
- cmpl 8(%esp), %eax /* Is a >= b? */
- jge done /* yes, return a (already in EAX) */
- movl 8(%esp), %eax /* no, return b */
- done:
- ret
Add Comment
Please, Sign In to add comment