3.58 The code that follows shows an example of branching value in a switch state
ID: 3700519 • Letter: 3
Question
3.58 The code that follows shows an example of branching value in a switch statement. Recall that enumerated types in to introduce a set of names having associated integer values. by assigned to the names go from with the different case labels have been omitted. on an enumerated type zero upward. In our code, the actions associated Enumerated type creates set of constants numbered o typedef enum {MODEA, MODE-B, MODE-C. HODE-D. HODE-E} and upvard ode-t; int svitch3(int pi, int .p2, mode.t action) int result -0; svitch(action) case MODE A: case MODE B: case MODE C case MODE D: case MODE E: default: return result; The part of the generated assembly code implementing the different actions is shown in Figure 3.43. The annotations indicate the argument locations, the register values, and the case labels for the different jump destinations. Register Zedx corresponds to program variable result and is initialized to-1. Fill in the missing parts of the C code. Watch out for cases that fall throughExplanation / Answer
int switch3(int *p1, int *p2, mode_t action){
int result =0;
switch(action) {
case MODE_A: result = *p1+*p2;
case MODE_B: result = 2*(*p2)+*p1;
case MODE_C: result = *p1+15;
case MODE_D: result = *p1+17;
case MODE_E: result = 17 ;
default:
}
return result;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.