Assembly Code to C -
I was practicing some assembly code for C and need some help with two questions based on GCC objdump But it seems fine, but I want to make sure that I can do this without a computer (still new to assembly code)
Question 1:
q1: pushl% ebp movl% esp,% ebp subl $ 4,% esp cmpl $ 0, 8 (% ebp) \\ comparison zero to zero jle .L2 \\ jump if less than zero Or equal Movl $ 1, -4 (% ebp) \\ ?? Variable 2 = 1 ?? Jmp .L4 \\ Other .2: movl $ 0, -4 (% ebp) \\ variable2 = 0.4: movl-4 (% ebp),% eax \\ variable2 = leave variable 1
< / Pre>What got me
int main (int x, int z) {if (x <0) z = 0; Second z = x; }
But I was not sure what the purpose of
movl $ 1, -4 (% ebp)
was.Question 2:
Funnels: pushl% ebp movl $ 1,% eax movl% esp,% ebp movl 8 (% ebp) ,% Edx cmpl $ 1,% edx \\ variable 1 compare 1 jale.4.4 \\ little or equal jumping .5: emul% adx,% ex \\ variable 2 subl $ 1,% edx \\ variable -1 Compare the variable 1 with -1 equals 1 $,% ADX = 1. The .5 loop is not equal to 1 loop. 4: popl% ebp \\ Return Value Comment
How I interpreted the information
< P> Not sure my argument is right from both of them.int main (int x) {int result; If the (result = 1; x! = 1; x = x-1) result for (x & lt; = 1) {*} = x;} and {return result;}}
Q1 You have an argument Q2 8 (% ebp)
-4 (% ebp)
. The return value will be in % eax
. To know this, the function looks more like:
int foo (int arg) {int local; If (RAG and LT; = 0) {local = 0; } And {local = 1; } Return local; }
popl% ebp // return value
is not a return value, which is saved % ebp < / Collar collar (which was pushed in the beginning). In addition, the condition of the loop
for the loop & gt;
not ! =
. will be used to
- while
loop. Otherwise you get this function right.
int factorial (int x) {int result = 1; If (x> 1) {do} {result * = x; X - = 1; } While (x! = 1); } Return results; }
Comments
Post a Comment