Exercise 4 Loops Consider the following assembly code for a function F4 containi
ID: 3716543 • Letter: E
Question
Exercise 4 Loops Consider the following assembly code for a function F4 containing a loop F4: push EBP mov EBP, ESP # setup stack mov EDX, DWORD PTR [ebp+12] mov ECX, DWORD PTR [ebp+8] xor EAX, EAX mp .L2 dec ECX inc EDX inc EAX #ECX x #EAX ·L1 : ·L2 : cmp ECX, EDX #if # goto .L1 SAL EAX, 3 mov DWORD PTR [EBP-4], EAX mov ESP, EBE # ignore for now # cleanup stack pop EBP ret Complete the C code below corresponding to the assembly code above. You may only use the symbolic variables x, y, and result in your expressions below. Do not use register names int F4 (int x, int y) int result; return result;Explanation / Answer
Code:-
int F(int x,int y)
{
int z=5; //mov DWORD PTR [ebp-4], 5
int sum=y; // mov eax, DWORD PTR [ebp+8]
sum=sum+x; //add eax, DWORD PTR[ebp+12]
y=sum; //mov DWORD PTR [ebp+8], eax
sum=z; // mov eax, DWORD PTR [ebp-4]
y=y-sum; //sub DWORD PTR [ebp+8], eax
sum=y; //mov eax, [ebp+8]
return sum; //ret
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.