NASM - The Netwide Assembler

NASM Forum => Other Discussion => Topic started by: hockey97 on June 15, 2014, 06:31:42 PM

Title: Can someone convert this ASM code to C?
Post by: hockey97 on June 15, 2014, 06:31:42 PM
Hi, I  am learning ASM x86 and got this code for an example. I would like if someone could convert it from ASM to C or C++. Also explain what each line does.

I am new here and I know the basics of ASM. I am now trying to learn how to translate ASM code to C or a higher language.

Here's the code:

UnknownFunction:
    MOV EDI,EDI
    PUSH EBP
    MOV EBP,ESP
    MOV EAX,DWORD PTR SS:[EBP+8]
    XOR EDX,EDX
    LEA ECX,DWORD PTR DS:[EAX+4]
    MOV DWORD PTR DS:[EAX],EDX
    MOV DWORD PTR DS:[ECX+4],ECX
    MOV DWORD PTR DS:[ECX],ECX
    MOV DWORD PTR DS:[EAX+C],ECX
    MOV ECX,DWORD PTR SS:[EBP+C]
    MOV DWORD PTR DS:[EAX+18],ECX
    MOV ECX,DWORD PTR SS:[EBP+10]
    MOV DWORD PTR DS:[EAX+1C],ECX
    MOV ECX,DWORD PTR SS:[EBP+14]
    MOV DWORD PTR DS:[EAX+20],ECX
    MOV ECX,DWORD PTR SS:[EBP+18]
    MOV DWORD PTR DS:[EAX+14],EDX
    MOV DWORD PTR DS:[EAX+10],EDX
    MOV DWORD PTR DS:[EAX+24],ECX
    POP EBP
    RETN 14


All I know is that it's pushing stuff off and on a stack. It has pointers and uses exclusive or conditional statement.

I am guessing that RETN 14 is the same as returning 0 in C or C++.
This whole thing is a function.
Title: Re: Can someone convert this ASM code to C?
Post by: gammac on June 16, 2014, 10:46:54 AM
I am sure, you won't learn assembly programming by the use of reverse engeneering!
Title: Re: Can someone convert this ASM code to C?
Post by: encryptor256 on June 17, 2014, 08:51:33 AM
I am guessing that RETN 14 is the same as returning 0 in C or C++.

I think, Your "quessing" is a bit wrong. It pops 14 bytes off the stack and only then - returns. Returns value that is stored into eax.

Thanks, bye.
Title: Re: Can someone convert this ASM code to C?
Post by: hockey97 on June 18, 2014, 02:58:42 AM
I am guessing that RETN 14 is the same as returning 0 in C or C++.

I think, Your "quessing" is a bit wrong. It pops 14 bytes off the stack and only then - returns. Returns value that is stored into eax.

Thanks, bye.

So, then how would you write that in C or C++?
Title: Re: Can someone convert this ASM code to C?
Post by: franciscamitchell on July 07, 2014, 09:32:13 AM
I have seen a couple applications that can do that but the code you will get will not be anything similar to the original code. I just complete an assignment about conversion of ASM to C with the help of genuine essay writing service (http://www.essayscouncil.com/essays.php), but i can't follow the method described in it. I think that to call assembly from C, you simply use the normal C syntax for a function call. This assumes, of course, that the assembly function was written using the C calling conventions.
Title: Re: Can someone convert this ASM code to C?
Post by: jiminan on August 30, 2014, 09:23:01 AM
I have seen a couple applications that can do that but the code you will get will not be anything similar to the original code. I just complete an assignment about conversion of ASM to C with the help of genuine essay writing service (http://www.essayscouncil.com/essays.php), but i can't follow the method described in it. I think that to call assembly from C, you simply use the normal C syntax for a function call. This assumes, of course, that the assembly function was written using the C calling conventions.

I'm absolutely agree with you .
Title: Re: Can someone convert this ASM code to C?
Post by: haliesean55 on July 23, 2016, 11:23:15 AM
Your assigned essay writer will handle every aspect of formatting to ensure that you receive buy narrative essay (http://www.buy-essay-online.com/) and submit a properly formatted essay.