View previous topic :: View next topic |
Author |
Message |
hitmetwice Advanced Cheater
Reputation: 0
Joined: 20 Nov 2012 Posts: 63
|
Posted: Thu Oct 03, 2013 12:09 pm Post subject: [ASM] How do functions work/look like? |
|
|
Could you give me some examples of how a function looks like in assembly and what the code that calls it would look like?
For example:
Code: | int Add(int x, int y) {
return x + y;
} |
and
Code: | int result = Add(12, 3); |
|
|
Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
|
Back to top |
|
 |
justa_dude Grandmaster Cheater
Reputation: 23
Joined: 29 Jun 2010 Posts: 891
|
Posted: Sat Oct 05, 2013 5:01 pm Post subject: |
|
|
Most C and C++ compilers also provide a switch that will cause them to generate assembly code, even if it isn't an explicit intermediate step. For simple examples, like yours, it may be useful for study purposes.
|
|
Back to top |
|
 |
hitmetwice Advanced Cheater
Reputation: 0
Joined: 20 Nov 2012 Posts: 63
|
Posted: Sat Oct 12, 2013 2:06 am Post subject: |
|
|
Thank you guys, this helps a lot.
Does a function in assembly always start with "PROC "?
I'm just wonderung because when I browse through the memory with CE and rightclick different addresses and say "Select current function", the selected functions have very different beginnings like cmp, push, mov.
This feature of CE does really confuses me and I'm not sure if I use it correctly.
|
|
Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Sun Oct 13, 2013 6:38 am Post subject: |
|
|
The 'PROC' & 'ENDP' are just keywords for the compiler to know whether a new procedure started / ended.
when the code is assembled into a binary format there are no 'proc' or labels etc... they translated into addresses
In the same manner i could write a function like that
Code: |
my_function:
push ebp
mov ebp,esp
// my_function code
leave
retn
// my main
// some code
call my_function
// continue with rest of the code
|
when you disassemble the code using CE you won't see 'my_function' label, but an address that my_function is located at.
and for the push ebp, mov ebp,esp instructions, every function starts in it's own way, it could start however the programmer wants.
the popular way is storing ebp register so you won't lose it's value and then make him point to the top of the stack because esp always changes and you want a a nice and tidy access to the parameters that are stored in the stack instead of calculating every time where the parameters are relatively to esp.
_________________
Stylo |
|
Back to top |
|
 |
|