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 switch(short x, short \*dest) {
short val = 0;
switch (x) {
.
.
Body of switch statement omitted
}
\*dest = val;
}
In compiling the function, gcc generates the assembly
code that follows for the initial part of the procedure, with
variable x in %rdi:
; void switch(short x, short *dest)
; x in %rdi
switch:
addq $2, %rdi
cmpq $8, %rdi
ja .L2
jmp *.L4(, %rdi, 8)
Based on this information, answer the following questions:
Question 13
What is the maximum case
label in the above code?
For example, in the following code,
the maximum case label is 7.
void switcher(long a, long b, long c, long *dest)
{
long val;
switch(a) {
case 5:
c = b ^ 15;
/* Fall through */
case 0:
val = c + 112;
break;
case 2:
case 7:
val = (c + b) << 2;
break;
case 4:
val = a;
break;
default:
val = b;
}
*dest = val;
}
Answer:
Question 14
What is the minimum case
label in the above code?
For example, in the following code,
the minimum case label is 0.
{
long val;
switch(a) {
case 5:
c = b ^ 15;
/* Fall through */
case 0:
val = c + 112;
break;
case 2:
case 7:
val = (c + b) << 2;
break;
case 4:
val = a;
break;
default:
val = b;
}
*dest = val;
}
Answer:
In the C function that follows, we have omitted the body of the switch statement. In the C code, the case labels did not
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
In the C function that follows, we have omitted the body of the switch statement. In the C code, the case labels did not
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!