Question: Problem 2 Write the C code that produces the assembly code you were provided in lab w4. The switch statement is in main, not in

Problem 2 Write the C code that produces the assembly code you were provided in lab w4. The switch statement is in main, not in another function, we apologize of that typo caused any problems during lab. The assembly code and the jump table are provided here:

(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 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!