Practice Problem 3.30 (solution page 338)
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(long x, long *dest) {
long val = 0;
switch (x)t {
.
. 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:
It generates the following code for the jump table:
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?
Want to see the full answer?
Check out a sample textbook solutionChapter 3 Solutions
Computer Systems: A Programmer's Perspective (3rd Edition)
Additional Engineering Textbook Solutions
Starting Out With Visual Basic (8th Edition)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Computer Science: An Overview (12th Edition)
Java How To Program (Early Objects)
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
- Question is to expand on current code.(program written in C) (3) Extract the two words from the input string and remove any spaces. Store the strings in two separate variables and output the strings. Ex: Enter input string: Jill, Allen First word: Jill Second word: Allen CURRENT PROGRAM: #include <stdio.h> #include <string.h> #include <stdlib.h> #define MAX_LIMIT 50 //Function definitionint Commacheck(char *input) { int flag = 0; for(int i = 0; i < strlen(input); i++) { //if comma is present in the input entered by user, update the fag to 1. if(input[i] == ',') { flag = 1; break; } } return flag; }//Main functionint main(void) { //varaiable initialization char input[MAX_LIMIT]; char *word[2]; char delimiter[] = ", "; printf("\n"); //get the input string from the user printf("Enter input string: ");…arrow_forward(QI. 5.) Write a C++ class member function to print alternate nodes of the given Linked List, first from head to end, and then from end to head. If Linked List has even number of nodes, then function skips the node. (Example: Input: 1->2->3->4->5, output: 13553 1).arrow_forward(Chapter 10) Here again is the example used in our lecture to show the difference between scoping with blocks and dynamic scoping; fun g x = let val inc = 1; fun f y = y + inc; fun h z = let val inc = 2; in f z end; in h x end; Annotate it as follows: Draw a circle around every block, and number the blocks. Identify each definition of a name. For each definition, describe its scope in terms of your block numbers. For each occurrence of a name (other than a definition of that name), show which definition is used to bind it. Check that this agrees with your scopes.arrow_forward
- [5] You are given the following information. A function with prototype Void decode1( int *xp, int *yp, int *zp); Mov edi,8[ebp] Mov edx,12[ebp] Mov ecx, 16[ebp] Mov ebx, [edx] Mov esi, [ecx] Mov eax, ledij Mov [edx],eax Mov [ecx],ebx mov [edi),esi Parameters xp, yp, and zp are stored at memory locations with offsets 8, 12, and 16, respectively, relative to the address in register %ebp. Write C code for decode1 that will have an effect equivalent to the assembly code above. o-Cemputer stes 5. Notes 回 品arrow_forwardPlease write a C++ coding with modularity using functions. 15. (Numerical) a. Euclid’s method for finding the greatest common divisor (GCD) of two positive integers consists of the following steps:Step 1: Divide the larger number by the smaller and retain the remainder.Step 2: Divide the smaller number by the remainder, again retaining the remainder.Step 3: Continue dividing the previous remainder by the current remainder until the remainder is zero, at which point the last non-zero remainder is the GCD. For example, if the two positive integers are 84 and 49, you have the following: Step 1: 84/49 yields a remainder of 35.Step 2: 49/35 yields a remainder of 14.Step 3: 35/14 yields a remainder of 7.Step 3: 14/7 yields a remainder of 0. Therefore, the last non-zero remainder, which is 7, is the GCD of 84 and 49.Using Euclid’s algorithm, replace the stub function written for Exercise 14 with an actual function that determines and returns the GCD of its two integer arguments. thank you…arrow_forward12. (identities). Minimize the function F using algebraic modifications (w,x,y,z) Y(Z+WX (W+Z)) + (XY+(x+y) + Z) + z ((ZX +2X) A M+1) = 12²x²x²m)_]arrow_forward
- Problem 17. [ 1 point for correctness ] Use the Design Recipe to define a function pulse_rate that has two parameters. The first is the number of seconds a nurse has counted pulses, and the second is the number of pulses counted (both ints). The function should return the pulse rate, pulses/minute, as a float. Don't forget to convert seconds to minutes! Include a Docstring.(use Python) For example: Test Result print(round(pulse_rate(30,22),1)) 44.0 Use this statement to test your pulse_rate function: assert_equal(round(pulse_rate(30, 22),1),44.0)arrow_forward4) Write a function in C to find sum of the following series- −2 + 4 − 6 + 8... (for, while)Function prototype - int getSeriesSum(int n)arrow_forwardProblem 4 (Searching a list of Student objects)Write a function called find_by_ID(students, id) that takes a list of student objects(students) and an int (id) as parameters, and returns the student object in the list withthe given id. If there is no student with the given id, it returns “NA”.See the sample output below. Looking for a student with ID = 123: Student: Alice, ID# 123 found Looking for a student with ID = 999: Student: Cathy, ID# 567 foundLooking for a student with ID = 555: NA foundarrow_forward
- Example 7: Code the below problem using C++ Sample Input: 1. 4 1234 Sample Output: 16 Ayush has an array a of n integers. He wants to collapse the entire array into a single element. To do this, he can perform the operation described below any number of times. Each operation grants some points, and Ayush's total score will be the sum of the points granted over all operations he performs. Let aſi..j] denote the subarray of a starting at index i and ending at j. Define min; j to be the minimum value in a[i..j]. In one operation he can do the following: • Select any subarray a[i. j] of a of size at least 2 and replace this subarray by a single element equal to the sum of elements of the subarray. The number of points granted by such an operation, which will be added to his total score, is (j – i+1) · min;j. For example, consider an array a = [2, 3, 5]. If he selects the subarray a[1..2], his total score increases by 2 · 2 = 4 points. Now a = [5, 5]. Ayush performs operations until only a…arrow_forwardComputer Science c++ || urgent Write the code for choosing the list of items in order to get the maximum profit of fractional knapsack problem. [NOTE: number of input items should be user interest, and output should be like - firstly print the resulting profit table, and then print the all selected items (must not be all items from the inputted items - means that all inputted items should not be as the selected items) for the knapsack and then print the maximum profit.]arrow_forwarda)Write the python code about lot sizing with capacity constraints such asr=(20,40,100,35,80,75,25)c=(60,60,60,60,60,60,60)where r is demand and c is capacityb) think about an example which has not the same capscity values. How will be your answer changed at that time?arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education