Question: In the C function that follows, we have omitted the body of the switch statement. In the C code, the case labels did not span

In the C function that follows, we have omitted the body of the switch statement. In the C code, the case labels did not span a contiguous range, and some cases had multiple labels.

void switch2(short x, short *dest) { short val = 0; switch (x) { } Body of switch statement omitted } *dest =

In compiling the function, gcc generates the assembly code that follows for the initial part of the procedure, with variable x in %rdi:

1 2 3 4 5 void switch2 (short x, short *dest) x in %rdi switch2: addq cmpq ja jmp $2, %rdi $8, %rdi .L2 *. L4

It generates the following code for the jump table: 1 .L4: 2 3 34 5 6 7 8 9 10 .quad . quad .quad - quad

Based on this information, answer the following questions:

A. What were the values of the case labels in the switch statement?

B. What cases had multiple labels in the C code?

void switch2(short x, short *dest) { short val = 0; switch (x) { } Body of switch statement omitted } *dest = val;

Step by Step Solution

3.52 Rating (179 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

This problem gives you a chance to reason about the control flow of a switch statement Answering the ... View full answer

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 Computer Systems A Programmers Perspective Questions!