x at %ebp+8
movl 8(%ebp) ,%edx ; moving x in edx
movl $0 ,%eax ;moving 0 in eax
testl %edx,%edx ;if edx is zero jump at .L7
je .L7
.L10
xorl %edx,%eax ; take xor of edx and eax and put in to eax
shrl %edx ; shift by 1 to right
jne .L10 ;jump to .L10 if not equal to zero
.L7
andl $1,%eax ;take and with 1 of eax as output
//Your C code
int fun_a(unsigned x) { int val = 0; while(x != 0) { val ^= x; x>>=1; } return val & 1; }
This function returns 1 if x has odd number of 1's in its binary representation as, 2,4,7 etc.
This function returns 0 if x has even number of 1's in its binary representation as, 0,3,5,6 etc.
//if you have any doubt.Please feel free to ask.
Thanks
A function, fun_a, has the following overall structure: int fun_a(unsigned x) I int val 0 while r...
For the C code 1 int loop while(int a, int b) int result 1; while (a < b) t result (atb); return result; Gcc generates the following assembly code: %ebp+8, mov1 movl movl %ebp+12 at 8(%ebp) ,%ecx 12(%ebp) ,%ebx $1,%eax a at b 5 jge L11 leal (%ebx, %ecx), Xodx 8 L12: inull %eax , %eax addl $1,%ecx addl $1, edx cmp1 %ecx , %ebx 9 10 12 13 J8 14 ·L11: .L12 In generating this code, occ makes an...
A C function fun has the following code body: *p -d; return x-c; The IA32 code implementing this body is as follows 12 (%ebp) ,%eax 16(%ebp) , movabl nov1 nov1 %edx ,(%eax) movsw1 8(%ebp),%eax movl 20 (ebp), %edx subi %eax,%edx movi %edx, %eax 2 %eax 4 7 Write a prototype for function fun, showing the types and ordering of the arguments p, d, x, and c. A C function fun has the following code body: *p -d; return x-c; The...
Problem 2 Consider the following source code, where R, S, and T are constants declared with #define. long int AIRISJIT int store_ele(int h, int i, int j, long int 'dest) Alh][i]01-.dest; return sizeof(A) In compiling this program, GCC generates the following assembly code (with-02) store_ ele: movslq %esi, %rsi movslq %edi, %rdi movq (%rcx), %rax leaq (%rdi,%rdi,4), %rdi leaq (%rsi,%rsi,4), %rcx movslq %edx, %rdx addq %rcx, %rdx movq %rax, A( %rdx,8) movl $1120, %eax ret Create a text file to...
Consider the following source code, where b, c, and d are constants declared with #define. You will need to determine the values for b, c, and d. struct lnode { char *str; struct lnode *next; } struct lnode A[b][c][d]; int store_ele(int h, int i, int j, struct lnode dest) { A[h][i][j] = dest; return sizeof(A);} On compiling this program (with -O2), GCC generates the following assembly code for the store_ele function: store_ele: movslq %edi, %rdi movslq %esi, %rsi movslq %edx,...