0

I have the following function in assembly, but I need it in C. The code is:

push    ebp
mov ebp, esp
mov eax, DWORD PTR [ebp+8]
add eax, 1667940388
pop ebp
ret

Could anybody translate this into C for me. Thanks.

7
  • 5
    homework? what did you do so far? Commented Oct 1, 2014 at 17:57
  • I literally don't know assembly thats why I'm asking. Trying to learn as I go but its for intro CTF. Just want to make sure I'm on the right track understanding everything. Commented Oct 1, 2014 at 17:57
  • 1
    Then post what you think it means, we can help you understand if you're on the right track. Commented Oct 1, 2014 at 17:57
  • @DaleLakes take a look at CSAPP. it tells a lot. Commented Oct 1, 2014 at 17:59
  • So far I know eax is a 32-bit integer representation of ebp (I think). Then you add that number and eax together. What gets returned though? Commented Oct 1, 2014 at 18:01

1 Answer 1

1

Sorry for the silly mistake on the eax return value ... its' fixed now ... my assembly is a little rusty :)

int function(int value) 
{
    return value + 1667940388;
}
Sign up to request clarification or add additional context in comments.

6 Comments

it actually returns the value (in eax)
it's not correct. eax is return register. it return a value.
Ok that's what I was thinking. What does the ebp+8 do? Thats the only part I don't get.
The function's argument was pushed on the stack by the caller, then the function's return address. The function then pushes ebp on the stack then sets ebp to the current stack pointer. By that point, ebp+8 points to the function's argument (ebp+0 is the saved ebp value, ebp+4 is the return address) - this being 32-bit code of course.
Ok. So if I have 2 variables in the function's argument, then ebp+8 would be the first argument and ebp+12 would be the second?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.