Please give explanation as well Consider the following assembly code fragment: :
ID: 3810821 • Letter: P
Question
Please give explanation as well
Consider the following assembly code fragment: : push %ebp mov %esp, %ebp mov 0 times 8(%ebp), %eax and $0 times 1, %eax test %eax, %eax jne .L1 mov 0 times 8(%ebp), %eax add $0 times 2, %eax jmp .L2 .L1: mov 0 times 8(%ebp), %eax add $ 0 times 1, %eax .L2: pop %ebp ret If 0 times 8 (%ebp) correspond to the function argument n, which one of the following choices correctly denotes the C equivalent of assembly code fragment above? int func(int n) {if(n%2 == 0) return n+2; else return n+1;} int func(int n) {if(n%2 == 0) return n+1; else return n+2;} int func(int n) {if(n%2 ! = 0) return n+2; else return n+1;} int func(int n) {if(n+1)%2 == 0) return n+1; else return n+2;} int func(int n) {if(n%4 == 0) return n+2; else return n+1;}Explanation / Answer
Solution: (b)
int func(int n)
{
if(n%2==0)
return n+1;
else
return n+2;
}
Explanation: