I code use some help with this coding question: 2. Analyze the x86-64 assembly g
ID: 3827186 • Letter: I
Question
I code use some help with this coding question:
2. Analyze the x86-64 assembly given below.
Q2:
cmpl %esi, %edi # The parameters are passed in registers.
movl %esi, %eax
cmovge %edi, %eax #This is called a conditional move.
ret
Note: this function has been optimized and doesn't manipulate the stack. Registers store the parameters, recall which registers hold parameters.
a) [20 points] Assume the function is named Q2. Suppose that any parameters are named P1, P2, etc., in the order the parameters would be listed in the C code. Suppose the local variables are called L1, L2, etc., in the order they occur in the assembly code.
Write C code for the function that could have yielded the x86-64 assembly code given above, in the provided .c file. Your final answer must not include any goto statements! Be advised: you may derive a perfectly acceptable answer and find that when you compile it you get slightly different assembly code. Minor differences should be expected, so don't tweak your C code trying to replicate the assembly code exactly.
#include <stdlib.h>
#include <stdint.h>
//
//
//
//
int Q2(int P1, int P2)
{
// Reverse engineered code here.
return 0;
}
Explanation / Answer
#include <stdlib.h>
#include <stdint.h>
int Q2(int P1, int P2)
{
int z = P1;
if (P2 >= P2)
z = P2;
return z;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.