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: A Programmer's Perspective (3rd Edition)
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)
- Demonstrate how the gdb debugger can be utilized in aiding the establishment of Pointer assignment error language: C Perform debugging in Ubuntu Linux 16, i.e. Use only the gdb debugger. give the following screenshots:1code 2load program to gdb 3set break point 4fixed code 5load proggram ingdb again with fixed codearrow_forwardGiven the code segment below, what is the value that is passed to func() given the function call? Assume that func() is defined. If it is an invalid access, write INVALID (in all capital letters) as your answer. Assume that the array aData[] is associated to the memory address 1010 (in decimal). If the value is an address, then indicate the memory address in decimal. double aData[15] = {0.0, 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9};func(aData + 2);arrow_forwardIN asmly language please Pretty please with successful build screen shot and output 1.Using the AddTwo program from Section 3.2 as a reference, write a program that calculates the following expression, using registers: A = (A + B) − (C + D). Assign integer values to the EAX, EBX, ECX, and EDX registers. Note: you can hard code integer literal onto the registers, e.g. mov eax,55 ; AddTwo.asm - adds two 32-bit integers.; Chapter 3 example .386.model flat,stdcall.stack 4096ExitProcess proto,dwExitCode:dword .codemain proc mov eax,5 add eax,6 invoke ExitProcess,0main endpend main 2. Listing File for AddTwoSum Generate a listing file for AddTwoSum.asm(in 3.4.3 of the text) and write a description of the machine code bytes generated for each instruction. You can write your descriptions directly over the .lst file. You might have to guess at some of the meanings of the byte values. Submit the .lst file with your description over it.…arrow_forward
- In C, write a function that gets 3 pointers int* a, int* b, int* c, and rotates the values in their addresses to the left. That is, a gets the value of b, b gets the value of c, and c gets the value of a. void rotate3 (int* a, int* b, int* c); For example, if we have int x=1, y=2, z=3, then after calling rotate3 (&x, &y, &z) we should have x==2, y==3, and z==1. if we have int x=7, y=1, z=6, then after calling rotate3 (&x, &y, &z) we should have x==1, y==6, and z==7.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_forwardThe 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_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_forwardThe program below uses pointer arithmetic to determine the size of a 'char'variable. By using pointer arithmetic we can find out the value of 'cp' and thevalue of 'cp+1'. Since cp is a pointer, this addition involves pointer arithmetic:adding one to a pointer makes the pointer point to the next element of the sametype.For a pointer to a char, adding 1 really just means adding 1 to the address, butthis is only because each char is 1 byte.1. Compile and run the program and see what it does.2. Write some code that does pointer arithmetic with a pointer to an int anddetermine how big an int is.3. Same idea – figure out how big a double is, by using pointer arithmetic andprinting out the value of the pointer before and after adding 1.4. What should happen if you added 2 to the pointers from exercises 1through 3, instead of 1? Use your program to verify your answer.#include <stdio.h>int main( ){ char c = 'Z'; char *cp = &c; printf("cp is %p\n", cp); printf("The character at cp is…arrow_forwardThe program below uses pointer arithmetic to determine the size of a 'char'variable. By using pointer arithmetic we can find out the value of 'cp' and thevalue of 'cp+1'. Since cp is a pointer, this addition involves pointer arithmetic:adding one to a pointer makes the pointer point to the next element of the sametype.For a pointer to a char, adding 1 really just means adding 1 to the address, butthis is only because each char is 1 byte.1. Compile and run the program and see what it does.2. Write some code that does pointer arithmetic with a pointer to an int anddetermine how big an int is.3. Same idea – figure out how big a double is, by using pointer arithmetic andprinting out the value of the pointer before and after adding 1.4. What should happen if you added 2 to the pointers from exercises 1through 3, instead of 1? Use your program to verify your answer.arrow_forward
- Inner 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_forwardJava programming Language Need help with Question 10.61arrow_forwardProgramme 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_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning