Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This problem will give you a chance to reverse engineer a switch statement from

ID: 3890714 • Letter: T

Question

This problem will give you a chance to reverse engineer a switch statement from machine code. In the following procedure, the body of the switch statement has been removed:

The disassembled machine code for the procedure is shown below. Recall parameter x is passed in register %rdi and parameter n is passed in register %rsi. The jump table resides in a different area of memory. We can see from the mov at address 0x040065e that the jump table begins at address 0x0400798. Using the gdb debugger, we can examine the ten 8-byte words of memory comprising the jump table with the command x/10x 0x400798. gdb prints the following:

Explanation / Answer

Not sure what needs to be answered here, but to test your disassembly, you could test your solution by writing a driver program like below -

--------------------------------------------------

#include <stdio.h>

long switch_prob(long x, long n) ;

int main () {

printf("%d ", switch_prob(100, 200));

return 0;

}

-----------------------------------------------------------------------------

Now you can compile the assembly code -

gcc -Wall questiontest.c test-assembly-switch.s

--------------------------------------------------------------------------------------------

Now you can edit your questiontest.c file and match the argumnents you passed in the driver program, to see if it actually holds.