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

9. (10 pt) A jump table begins at address Ox80485d0. The gdb debugger shows that

ID: 3891756 • Letter: 9

Question

9. (10 pt) A jump table begins at address Ox80485d0. The gdb debugger shows that eight-word spaces of jump table have the following values 0x80485d0: 0x08048438 0x08048448 0x08048438 0x0804843d 0x80485e0: 0x08048442 0x08048445 0x08048438 0x08048440 Fill in the body of the switch statement with C code so that it captures the behavior of the IA32 assembly code on the right. int sp(int x, int n) 08048420 : 08048420: pushl%ebp 08048421: movl %esp,%ebp 08048423: movl 0x8(%ebp), %eax 08048426: movl 0xc(%ebp), %edx 08048429: subl $0x32, %edx 0804842c: cmpl $0x5, %edx 0804842: ja 8048448 08048431: jmp *0x80485do(,%edx,4) 08048438: shil $0x2, %eax 0804843b: jmp 804844b 0804843d: sarl $0x2,%eax 08048440: jmp 804844b

Explanation / Answer

int sp(int x, int n)

{

int result = x;

switch(n)

{

/*values less than 50 will be negative, so unsigned comparison will return n > 55 */

case 50:

case 52:

x = x << 2;

break;

case 53:

x = x >> 2;

break;

case 54:

x *= 3; /*lea exploitation*/

/*no break*/

case 55:

x *= x;

case 51: /*default*/

default: /*n > 55*/

x += 10;

}

return result;

}