Question: This problem pertains around assembly code and programming C. Problem 4 (Conditioral moves and jumps.) A. The following assembly code implements a simple function whose

This problem pertains around assembly code and programming C.

This problem pertains around assembly code and programming C. Problem 4 (Conditioral

Problem 4 (Conditioral moves and jumps.) A. The following assembly code implements a simple function whose definition has three different three cases: xorq %rax,trax movq $1, rdx testq %rdi, rdi Rewrite the function so that t computes the same result, but uses conditional jump instructions XX and labels, and does not use conditional move or set-condition (ovXX or setXX) instruc- tions B. (Based on the textbook problern 3.61.) The following C function kudsa 64-bit value from a pointer, but if the pointr is nu it just returns the value1, so it never dereferences a null pointer. long safe load (1ongp) if (p) return P return-1 move, since it would be bad to always dereference the pointer, and then return either the loaded value or based on whether the pointer wsnl. The function will crash at the time it tries to load from a null pointer, even if function a different structure to avoid this problem and sil use a conditional move. First, to get the core idea, show how to rewrite the function in C without any conditional side-effects. Specifically, write a function that has the same behavior, but does not use an iE statement or other control flow You should use the? ernary operator, but only in a case where all the arguments to the? are simple variables, (Hint: the function will still have to do a dereference, but the dereference will have to be unconditional. In other words, the function needs to dereference something every time in executes.) the loaded value is later not used. However, we could give the Now, write an assembly-language version based on your new C version, which uses only con- ditional move instructions, and no conditional jump instructions or labels. Problem 4 (Conditioral moves and jumps.) A. The following assembly code implements a simple function whose definition has three different three cases: xorq %rax,trax movq $1, rdx testq %rdi, rdi Rewrite the function so that t computes the same result, but uses conditional jump instructions XX and labels, and does not use conditional move or set-condition (ovXX or setXX) instruc- tions B. (Based on the textbook problern 3.61.) The following C function kudsa 64-bit value from a pointer, but if the pointr is nu it just returns the value1, so it never dereferences a null pointer. long safe load (1ongp) if (p) return P return-1 move, since it would be bad to always dereference the pointer, and then return either the loaded value or based on whether the pointer wsnl. The function will crash at the time it tries to load from a null pointer, even if function a different structure to avoid this problem and sil use a conditional move. First, to get the core idea, show how to rewrite the function in C without any conditional side-effects. Specifically, write a function that has the same behavior, but does not use an iE statement or other control flow You should use the? ernary operator, but only in a case where all the arguments to the? are simple variables, (Hint: the function will still have to do a dereference, but the dereference will have to be unconditional. In other words, the function needs to dereference something every time in executes.) the loaded value is later not used. However, we could give the Now, write an assembly-language version based on your new C version, which uses only con- ditional move instructions, and no conditional jump instructions or labels

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!