Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The following problem tests your understanding of switch statements that use jump tables. Consider a switch statement implemented by using the jmpq instruction to index

The following problem tests your understanding of switch statements that use jump tables. Consider a switch statement implemented by using the jmpq instruction to index into the jump table. The jump table is defined as follows:
0x400598: 0x00000000004004880x0000000000400488
0x4005a8: 0x000000000040048b 0x0000000000400493
0x4005b8: 0x000000000040049a 0x0000000000400482
0x4005c8: 0x000000000040049a 0x0000000000400498
Here is the assembly code for the switch statement:
# on entry : %rdx = c and %rsi = b
0x400474 : cmp $0x7,%edi
0x400477 : ja 0x40049a
0x400479 : mov %edi, %edi
0x40047b : jmpq *0x400598(,%rdi, 8)
0x400482 : mov $0x15213,%eax
0x400487 : retq
0x400488 : sub $0x5,%edx
0x40048b : lea 0x0(,%rdx,4),%eax
0x400492 : retq
0x400493 : mov $0x2,%edx
0x400498 : and %edx, %esi
0x40049a : lea 0x4(%rsi),%eax
0x40049d : retq
[continued on next page]
CS 33| SUMMER 2024| HOMEWORK 2 PAGE 4 Complete the TODO section such that the C code compiles to match given the
assembly code.
int main(int a, int b, int c){ int result =4;
switch (a){
/* TODO */
}
return result; }

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

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students also viewed these Databases questions