A C function looper and the assembly code it compiles to on an IA-32 machine run
ID: 3626119 • Letter: A
Question
A C function looper and the assembly code it compiles to on an IA-32 machine running Linux/GAS is shown below.looper:
pushl %ebp
movl %esp,%ebp
pushl %esi
pushl %ebx
movl 8(%ebp),%ebx
movl 12(%ebp),%esi
xorl %edx,%edx
xorl %ecx,%ecx
cmpl %ebx,%edx
jge .L25
.L27:
movl (%esi,%ecx,4),%eax
cmpl %edx,%eax
jle .L28
.L28:
incl %edx
incl %ecx
cmpl %ebx,%ecx
jl .L27
.L25:
movl %edx,%eax
popl %ebx
popl %esi
movl %ebp,%esp
popl %ebp
ret
I need the the C equivalent. (fill in the blanks)
int looper(int n, int *a) {
int i;
int x = ________;
for(i = _____;_______; i++) {
if (_______)
x = _____;
_____;
}
return x;
}
Explanation / Answer
Dear, Answers are highlifghted bold with RED Font int looper(int n, int *a) {int i;
int x = 0;
for(i = 0; i< n ; i++) {
if (a[i] > x)
x = a[i] ;
x++;
}
return x;
} Hope this will help you
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.