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

  int main (int x) {int result; If the (result = 1; x! = 1; x = x-1) result for (x & lt; = 1) {*} = x;} and {return result;}}  
< P> Not sure my argument is right from both of them.

Q1 You have an argument 8 (% ebp)

and -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; }  

Q2 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 & gt; not ! = . will be used to (x> 1) for the loop around the code (to present it, Thanks to.) Also, technically it has to do a - 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

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -