I work in malware analysis . We aren't compiling at all , but rather needing to take the malware back to a (at least pseudo)source to get a feel for impact and understanding the complexity of what we are working against.

You cannot directly convert assembly to c++ . Such a thing will probably not exist; maybe in the late future if at all.

I usually convert if over to C and then work on to C++ and the key word here was directly. I suppose you could do this as c++ , I think certain areas would be difficult but possible with time.

This leads to my next point: The assembly you've shown us probably wasn't compiled using the highest level of optimisation, and if it was then it was compiled using a rather poor quality compiler. I would expect a decent optimising compiler to inline such a small function, since it's less code to just add the numbers than it is to call the function that adds the numbers.

It was compiled using gcc, which isn't terrible(I personally, have a bit of a love affair with it). I think all compilers make these kinds of mistakes, which is why optimization is important. I also don't think I have ever worked with optimized assembly.... I imagine it is pretty nice.

I would like to make a tutorial series that would like to go into the many uses of assembly. I will see how that works out though.

@ Roger Pettersson You cannot directly convert assembly to c++ . Such a thing will probably not exist; maybe in the late future if at all.

The reason is the code in assembly is all opp codes and variables are typically stripped and with out symbols.

Humans however, are rather amazing computers. You can however learn to convert ASM into pseudo C like code and then into C++.

A program that does this is IDA PRO. Ida pro is great! I will admit it makes several mistakes some of which, being that variables will be doubled or you'll see it think that a function returns an int when the function is a void.

I found that one thing that helps reversing back to C++ is to use the libraries and calls that the program uses. So a program may use DDRAW or it might use user32 to call MessageBox; one should spend time in these languages to compile them and understand how the particular compiler will interpret that code to be.

This is just what every function does to save the return address when entering a function.

.text:00401344 and esp, 0FFFFFFF0h.text:00401347 sub esp, 20h

This is a funny thing that compilers do that will make you thing Really?! stupid computer! and operation is a way of doing binary math. In this case it will subtract ESP 8 which is odd considering the next instruction will subtract again another 0x20h ... so a human writing this would already optimize this by doing something like sub esp,28h.

mov [esp+20h+var_4], 0Fh ; movs 15 into a "safe" spot in the stackmov [esp+20h+var_8], 13h ; movs 19 into a "safe" spot in the stackmov eax, [esp+20h+var_4] ; movs 15 into EAXmov [esp+20h+var_1C], eax ; Again another sort of silly thing but not too bad; it moves 15 from EAX on to the second to the top of the stackmov eax, [esp+20h+var_8] ; moves the next variable into the top of the stack.

CALL 00401334

This is the function that we are calling with-in main I have named it functs() . because they're not any symbols we cannot see this for its name.it moves 15 to EAX and 19 to EDX.

with in functs we see

ADD EAX,EDX

So we see that the two numbers have been added and returns are made to EAX; so we have 34 or 0x22 currently in EAX;

mov [esp+20h+var_C], eaxmoves the total onto the stack

mov eax, [esp+20h+var_C]Again, an inefficient instruction its moving the total from the stack back into EAX which isn't needed at all.

mov [esp+20h+var_1C], eaxthen again it moves the total from eax to the second spot on the stack

mov [esp+20h+Format], offset Format ; "%d"moves 00403024 or "%d" to the top of the stack;

I would say that its a very logic step, programming in assembly, going from software to hardware or vice versa. Printed circuit board engineering (electronics) for example uses assembly logic "thinking". It might sometime see very basic looking at one NAND or OR gate truth-table. But set 10 or more of those in different connections and you have yourself a quite nasty boolean algebra problem to solve. But... this is just my experience, because i always ask myself how does it work ? What does it do ? What the hell is going on ? And every time i look at some programming language, i freak out. Because i cant translate it... but i would understand it more (in common sense) if it breaks down to assembly language.

From my case, i want to know where https://translate.google.com/ C++ to assembly is. Or any other language for that matter. Wouldnt it be lovely to have such a neat translator ? But i guess, sometimes, you must settle for less and dont bother about what is going on behind the scene and sit down and enjoy the movie. And i do like movies, not to mention computer games.

There is a nice video that brings this topic up actually. What good is assembly actually ?

hey, ofc that ASM is not really necessary for a high tech job, you won't be writing programs in ASM, but assembly is really gonna help to your programming skills, also i know that apple developers are required to know SOME assembly, so you don't really have to learn it, but if you do it's gonna only help you.