In Section 3.6.6, we examined the following code as a candidate for the use of conditional data transfer:
long cread (long *xp) {
return (xp ? xp : 0);
}
We showed a trial implementation using a conditional move instruction but argued that it was not valid, since it could attempt to read from a null address.
Write a C function cread_alt that has the same behavior as cread, except that it can be compiled to use conditional data transfer. When compiled, the generated code should use a conditional move instruction rather than one of the jump instructions.
Want to see the full answer?
Check out a sample textbook solutionChapter 3 Solutions
COMPUTER SYSTEMS&MOD MSGT/ET SA AC PKG
Additional Engineering Textbook Solutions
Differential Equations: Computing and Modeling (5th Edition), Edwards, Penney & Calvis
Experiencing MIS
Database Concepts (8th Edition)
Java: An Introduction to Problem Solving and Programming (7th Edition)
Starting Out with Java: Early Objects (6th Edition)
Starting Out with C++ from Control Structures to Objects (8th Edition)
- The read() system call needs to be run in a loop to deal safely with edge cases that can appear on some system configurations. Some libraries provide a function for this (for example the C library [fread), but it is not too hard to code yourself. Consider the following snippet of code, with two parts replaced by XXX and YYY ssize_t do_read(int fd, void buffer, size_t len) { ssize_t res; do { res read(fd, buf, len); while (res XXX @ && errno YYY); return res; } Enter the values for XXX and YYY to make this code run correctly, respecting the following rules. The correct value for XXX is a single operator. Enter it without any spaces. The correct value for YYY is a clause to do a comparison with the errno value. Enter the value with no leading or trailing spaces, and exactly one space in any places inside the string where spaces are required. Enter the values here: ● XXX: • YYY:arrow_forwardImplement in C Programming 6.10.1: Function pass by pointer: Transforming coordinates. Define a function CoordTransform() that transforms its first two input parameters xVal and yVal into two output parameters xValNew and yValNew. The function returns void. The transformation is new = (old + 1) * 2. Ex: If xVal = 3 and yVal = 4, then xValNew is 8 and yValNew is 10. #include <stdio.h> /* Your solution goes here */ int main(void) { int xValNew; int yValNew; int xValUser; int yValUser; scanf("%d", &xValUser); scanf("%d", &yValUser); CoordTransform(xValUser, yValUser, &xValNew, &yValNew); printf("(%d, %d) becomes (%d, %d)\n", xValUser, yValUser, xValNew, yValNew); return 0;}arrow_forward2. Implement the frame replacement algorithm for virtual memory In Java For this task, you need to perform the simulation of page replacement algorithms. Create a Java program which allows the user to specify: • the total of frames currently exist in memory (F), the total of page requests (N) to be processed, • the list or sequence of N page requests involved, For example, if N is 10, user must input a list of 10 values (ranging between 0 to TP-1) as the request sequence. Optionally you may also get additional input, the total of pages (TP) This input is optional for your program/work. It only be used to verify that each of the page number given in the request list is valid or invalid. Valid page number should be within the range 0, .. , TP-1. Page number outside the range is invalid. Then use the input data to calculate the number of page faults produced by each of the following page replacement algorithms: • First-in-first-out (FIFO) - the candidate that is the first one that entered…arrow_forward
- For the scramble.c problem, write a program that: • Has a main () function and another function that has this prototype: void scramble str (char s[]); • The scramble_str() function scrambles the contents of the string in a random way so that the string has the same length as before, but the contents are all mixed around. It does this in-place, i.e., there is only one buffer that holds a string. You're free to scramble it any way you want to, but use rand () repeatedly so it gets really scrambled. • The main () function will read a string entered by the user into the buffer, call scramble_str(), and output the resulting string. This will be done in a loop forever, until the entered string is the string "bye". When the user says "bye", the program will exit with a polite message. Do note that reading a string using scanf (), which is the only tool I've introduced you to so far, will just read up to the first whitespace. So, multiple-word strings won't work! Let's use something that will…arrow_forwardInner loop of inner4. data_t = double, OP = * udata in %rbp, vdata in %rax, sum in %xmmo i in %rcx, limit in %rbx 1 .L15: loop: vmovsd 0(%rbp,%rcx,8), %xmm1 vmulsd (%rax,%rcx,8), %xmm1, %xmm1 vaddsd %xmm1, %xmm0, %xmmo $1, %rcx %rbx, %rcx 2 Get udata[i] 3 Multiply by vdata[i] 4 Add to sum addq Increment i Compare i:limit If !=, goto loop стра 7 jne .L15 Assume that the functional units have the characteristics listed in Figure 5.12. A. Diagram how this instruction sequence would be decoded into operations and show how the data dependencies between them would create a critical path of operations, in the style of Figures 5.13 and 5.14. B. For data type double, what lower bound on the CPE is determined by the critical path? C. Assuming similar instruction sequences for the integer code as well, what lower bound on the CPE is determined by the critical path for integer data? D. Explain how the floating-point versions can have CPES of 3.00, even though the multiplication operation requires…arrow_forwardWrite a program in C++ that contains code addressing the following: (New code and with detailed steps!) a. Create an integer array of 100,000 items (static binding – before compiling) b. Create the same large array on the run time stack (in a function) c. Create the same large array from the heap (dynamic memory – dynamic binding). Call each of the subprograms 1,000,000 times and output the time required by each to finish all 1,000,000 calls. Which was the fastest? Here is code for calling time. #include <time.h> //in main() clock_t start = 0, end = 0; //variables start = clock(); //calls time function stores result in start end = clock(); // calls time function stores result in end //display the time by subtracting the start from the end //displays in clock ticks.arrow_forward
- The goal of this second exercise is to develop a better understanding of the Linuxinterprocess communication mechanisms. This would require you to write twoprograms P1 and P2. The first program P1 needs to generate an array of 50random strings (of characters) of fixed length each. P1 then sends a group offive consecutive elements of the array of strings to P2 along with the ID’s ofthe strings, where the ID is the index of the array corresponding to the string.The second program P2 needs to accept the received strings, and send backthe highest ID received back to P1 to acknowledge the strings received. Theprogram P2 simply prints the ID’s and the strings on the console. On receivingthe acknowledged packet, P1 sends the next five strings, with the string elementsstarting from the successor of the acknowledged ID. The above mechanism needs to be implemented FIFO and UNIX DOMAIN SOCKETS. Please note that you may NOT make assumptions about the reliability of the interprocess communication…arrow_forwardWrite a single and complete C program to help faculty ‘X’ preparing grades ofEEE 103:a. Ask the user how many students he has in his class and take it as input.b. Dynamically allocate memory and take input of the student’s EEE 103final marks using pointersc. Find the maximum marks obtained among them. The marks must beaccessed using pointer.d. Those who got below 50% of the maximum marks, add 2 marks bonus tothose student’s marks. The marks must be accessed using pointer.e. Consider the final exam has been taken for a total of 45 marks. But theweight of finals for the EEE 103 course is 32%. Now convert eachstudent's marks he received to 32% for preparing the grades. Store theconverted marks in another dynamically allocated array.f. Print the converted marks for all the students.arrow_forwardPlease written by computer source Question 1: Suppose we wish to write a procedure that computes the inner product of two vectors u and v. An abstract version of the function has a CPE of 14–18 with x86- 64 for different types of integer and floating-point data. By doing the same sort of transformations we did to transform the abstract program combine1 into the more efficient combine4, we get the following code: Our measurements show that this function has CPEs of 1.50 for integer data and 3.00 for floating-point data. For data type double, the x86-64 assembly code for the inner loop is as follows: Assume that the functional units have the characteristics listed in Figure 5.12. **See last page for figures A. Diagram how this instruction sequence would be decoded into operations and show how the data dependencies between them would create a critical path of operations, in the style of textbook Figures 5.13 and 5.14. vmovsd vmovsd vmulsd vaddsd | | | |…arrow_forward
- Programme In Dev C++ Need Code and output Q1. In this problem you have to take an array of size 10 and write the Enqueue, Dequeue and Display functions for that and also take care of overflow and underflow conditions. All the work must be done in classes. Furthermore you must write isEmpty(), isFull() and status() function. isEmpty() has return type of Boolean and check the underflow. isFull() has return type of Boolean and check the overflow. Status() tells the current available spaces in the stack. Also perform following function Create two objects of above class provide inputs and also check whether the two Queues are equal or not by writing equal() function In above case size of Queue is fixed do all the work with size provided by user.arrow_forwardAnswer it is c++ only Chef recorded a video explaining his favorite recipe. However, the size of the video is too large to upload on the internet. He wants to compress the video so that it has the minimum size possible. Chef's video has N frames initially. The value of the th frame is A₁. Chef can do the following type of operation any number of times: • Choose an index i (1 ≤ i ≤ N) such that the value of the ith frame is equal to the value of either of its neighbors and remove the ith frame. Find the minimum number of frames Chef can achieve. Input 1 1 5 output 1arrow_forwardThe question should be done in C++, please give explanation and running result. 1. For this question, we need to provide more information about where the mismatch of the text file is happening. Write a recursive function called list_mismatched_lines that takes 2 filenames as input arguments and displays to the screen all mismatched lines in those files. This function should use hashing techniques and shall not compare strings to detect mismatch. The signature of this function should be: void list_mismatched_lines(std::string file1, std::string file2); In file1.txt, it contains "My dear C++ class. I hope that you enjoy this assignment. " In file2.txt, it contains "My dear C++ class. I hope that you like this assignment. " Example: Running the following line of code, should print to the screen the mismatched lines only, from both files. list_mismatched_lines(file1, file2); The following output should be seen on the screen: file1.txt: I hope that you enjoy this assignment.file2.txt:…arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning