whats the conversion for this from C to x86 assembly language with intel notatio
ID: 3676639 • Letter: W
Question
whats the conversion for this from C to x86 assembly language with intel notation?
int performOperation (int operation, int first, int second)
{
if (operation==0)
return first + second;
else if (operation==1)
return first - second;
else if (operation==2)
return (first > second)? first : second;
else if (operation==3)
return (first < second)? first : second;
else
return first;
}
void vectorOperations (int number_of_elements, int *first_array, int *second_array,
int *operation_array, int *output_array)
{
int i;
for (i=0; i<number_of_elements; i++)
{
output_array[i] = performOperation(operation_array[i], first_array[i], second_array[i]);
}
}
Explanation / Answer
performOperation(int, int, int):
testl %edi, %edi
je .L11
cmpl $1, %edi
je .L12
cmpl $2, %edi
je .L13
cmpl $3, %edi
jne .L8
cmpl %edx, %esi
movl %edx, %eax
jl .L8
rep ret
.L11:
leal (%rsi,%rdx), %eax
ret
.L12:
movl %esi, %eax
subl %edx, %eax
ret
.L8:
movl %esi, %eax
ret
.L13:
cmpl %edx, %esi
movl %edx, %eax
cmovge %esi, %eax
ret
vectorOperations(int, int*, int*, int*, int*):
xorl %eax, %eax
testl %edi, %edi
jg .L26
jmp .L14
.L28:
addl %r11d, %r9d
.L17:
movl %r9d, (%r8,%rax,4)
addq $1, %rax
cmpl %eax, %edi
jle .L14
.L26:
movl (%rcx,%rax,4), %r10d
movl (%rdx,%rax,4), %r9d
movl (%rsi,%rax,4), %r11d
testl %r10d, %r10d
je .L28
cmpl $1, %r10d
je .L29
cmpl $2, %r10d
je .L30
cmpl $3, %r10d
jne .L23
cmpl %r11d, %r9d
jle .L17
.L23:
movl %r11d, %r9d
movl %r9d, (%r8,%rax,4)
addq $1, %rax
cmpl %eax, %edi
jg .L26
.L14:
rep ret
.L29:
subl %r9d, %r11d
movl %r11d, %r9d
jmp .L17
.L30:
cmpl %r11d, %r9d
cmovl %r11d, %r9d
jmp .L17
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.