I'm trying to disassemble a file, and one of the sections contained this. What is this doing? What would it look like in C?
I believe it copies 40 to ebp-8 and copies 20 to ebp-4. Then it calls the func: function. That performs a few commands by adding edx to eax and then subtracts 4 from it. After it exits the func: function it adds 8 to esp. Am I on the right track?
func:
push ebp
mov ebp, esp
mov edx, DWORD PTR [ebp+8]
mov eax, DWORD PTR [ebp+12]
add eax, edx
sub eax, 4
pop ebp
ret
main:
push ebp
mov ebp, esp
sub esp, 16
mov DWORD PTR [ebp-8], 40
mov DWORD PTR [ebp-4], 20
push DWORD PTR [ebp-4]
push DWORD PTR [ebp-8]
call func
add esp, 8
leave
ret
EDIT: So would you agree that the result of the C would be the following?
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
int func(int d, int e)
{
int sum = d + e;
int result = sum - 4;
return result;
}
int main(void)
{
int a = 40;
int b = 20;
int c = func(a,b);
printf("Result is: %d\n", c);
}