Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In the following procedure, the body of the switch statement has been removed: long switch_ prob(long x, long n) { long result = n; switch(x)

In the following procedure, the body of the switch statement has been removed:

long switch_ prob(long x, long n) 
{ 
long result = n; 
switch(x) { /* The code for the cases goes here */ } return result; } 

The disassembled machine code for the procedure is shown below. The jump table resides in a different area of memory. We can see from the mov at address 0x00000000004004dc that the jump table begins at address 0x4005b8. Using the gdb debugger, we can examine the eight 8-byte words of memory comprising the jump table with the command x/8x 0x4005b8. gdb prints the following:

(gdb) x/8x 0x4005b8 0x4005b8: 0x00000000004004e6 0x0000000000400516 0x4005c8: 0x00000000004004ed 0x0000000000400502 0x4005d8: 0x0000000000400516 0x0000000000400509 0x4005e8: 0x0000000000400516 0x000000000040050f

Dump of assembler code for function main: 0x00000000004004b6 <+0>: push %rbp 0x00000000004004b7 <+1>: mov %rsp,%rbp 0x00000000004004ba <+4>: mov %rdi,-0x18(%rbp) 0x00000000004004be <+8>: mov %rsi,-0x20(%rbp) 0x00000000004004c2 <+12>: mov %rdx,-0x28(%rbp) 0x00000000004004c6 <+16>: mov -0x18(%rbp),%rax 0x00000000004004ca <+20>: mov %rax,-0x8(%rbp) 0x00000000004004ce <+24>: mov -0x20(%rbp),%rax 0x00000000004004d2 <+28>: sub $0xd,%rax 0x00000000004004d6 <+32>: cmp $0x7,%rax 0x00000000004004da <+36>: ja 0x400516 0x00000000004004dc <+38>: mov 0x4005b8(,%rax,8),%rax 0x00000000004004e4 <+46>: jmpq *%rax 0x00000000004004e6 <+48>: addq $0xd,-0x8(%rbp) 0x00000000004004eb <+53>: jmp 0x40051e 0x00000000004004ed <+55>: mov -0x8(%rbp),%rdx 0x00000000004004f1 <+59>: mov %rdx,%rax 0x00000000004004f4 <+62>: shl $0x2,%rax 0x00000000004004f8 <+66>: add %rdx,%rax 0x00000000004004fb <+69>: add %rax,%rax 0x00000000004004fe <+72>: mov %rax,-0x8(%rbp) 0x0000000000400502 <+76>: addq $0x5,-0x8(%rbp) 0x0000000000400507 <+81>: jmp 0x40051e 0x0000000000400509 <+83>: shlq -0x8(%rbp) 0x000000000040050d <+87>: jmp 0x40051e 0x000000000040050f <+89>: shlq $0x3,-0x8(%rbp) 0x0000000000400514 <+94>: jmp 0x40051e 0x0000000000400516 <+96>: movq $0x0,-0x8(%rbp) 0x000000000040051e <+104>: mov -0x28(%rbp),%rax 0x0000000000400522 <+108>: mov -0x8(%rbp),%rdx 0x0000000000400526 <+112>: mov %rdx,(%rax) 0x0000000000400529 <+115>: pop %rbp 0x000000000040052a <+116>: retq

Questions:

(1)How many cases are specified in the switch statement?

(2)What is the smallest integral value specified for a case?

(3)What is the largest integral value specified for a case?

4) Give the address of where the code starts for the smallest integral value?

5) Specify the address of where the code starts for the largest integral value?

6) What is the address of where the code starts for the default case?

7) Give one case value that falls through to another case value.

8) List one integral value between the smallest and largest integral values (specified in 2 and 3 above) that goes to the default case.

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

Object Oriented Databases Prentice Hall International Series In Computer Science

Authors: John G. Hughes

1st Edition

0136298745, 978-0136298748

More Books

Students also viewed these Databases questions