Question: Complete the getbit function below. It returns the value of the ith bit of an integer (bit 0 is the rightmost bit). int getbit(int x)

Complete the getbit function below. It returns the value of the ith bit of an integer (bit 0 is the rightmost bit).

int getbit(int x) {

}

--> Consider the assembly language function p3 below. Note that jne is used somewhat differently than we have seen in the past, in that it is not immediately preceded by a comparison. Instead, it is the subl instruction which determines whether or not the jump takes place; specifically, the jump occurs if the result of the subtraction is nonzero.

(gdb) disas p3

Dump of assembler code for function p3:

0x400610 <+0>: test %esi,%esi

0x400612 <+2>: je 0x400623

0x400614 <+4>: nopl 0x0(%rax) # nopl ("no-op") does nothing and is for alignment

0x400618 <+8>: mov %esi,(%rdi)

0x40061a <+10>: add $0x4,%rdi

0x40061e <+14>: sub $0x1,%esi

0x400621 <+17>: jne 0x400618

0x400623 <+19>: retq

End of assembler dump.

The above assembly language was the result of compiling a C function of the format below. Your job is to fill in the missing pieces of the C code, so that it emulates p3. You will fill in 3 portions, each part is worth 1 point. The missing pieces are indicated by the dots below. Replace the dots and complete the C code.

void p3( ) {

int i;

for ( )

{ }

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!