Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

2. Identify issues/causes for the apparent conflict.

Answered: 1 week ago