previous | start | next

Reverse engineering: if statements

For the C code:

1 void cond(int a, int *p)
2 {
3   if (p && a > 0)  // Note: > has higher precedence
4      *p += a;
5 }

this IA32 assembly code is generated:

     1 movl 8(%ebp),%edx
     2 movl 12(%ebp),%eax
     3 testl %eax,%eax
     4 je .L3
     5 testl %edx,%edx
     6 jle .L3
     7 addl %edx,(%eax)
     8 .L3:
   
  1. Write an equivalent C "goto" version.

  2. Why are there 2 assembly jump statements for the single C 'if' statement?


previous | start | next