#cdecl
81 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
they don't cancel each other out
its just not necessarily important
they second instruction is irrelevant
well so its the first one but technically it does something
you copy a value from one place to another. Therefore both locations contain the same value
Therefore copying in the reverse is pointless since we already know both values contain the same value
this is unoptimized code
the first store is storing to sum
the load is loading from sum
into eax, which is the return register
i guess its a trick operation
but the value was in eax originally so this is pointless
the next question ask the state of the stack before leave instruction
no this is just what unoptimized code looks like
it does silly things like this because it doesn't know
what are you confused by?
in the CDECL calling convention the following holds:
Arguments are passed on the stack in Right-to-Left order, and return values are passed in eax.
okay lets say its saved like that
when we do
add eax,edx than the block where y is should have the value 12 right?
hmm
okay maybe they are right to left
AH
wait yes I misphrased
right to left and left to right depends on your perspective
they are pushed in right to left order
which means the most right will be deepest on the stack
you mean on the highest adress?
it will be the highest address yes because the stack grows downwards
hence why y is at the top
personally I think of that as left-to-right because of how Ive implemented it before, hence why I may have confused you
mov edx, DWORD PTR [ebp+8] so this saves x
yes
why is return address right before saved frame pointer(ebp?) is it the norm?
how could it not be?
the call instruction is what places that on the stack
before you even get to the current stack frame
call pushes the return address onto the stack
ret pops it off the stack
they point to different spaces
ebp and esp are the stack and base pointers
ebp points to the bottom of the stack
esp points to the top
oh
(which is actually below ebp but nevermind)
the bottom?
in a single stack frame btw, not necessarily the entire stack
oh the more you learn
well
when you enter a function you know 1 thing about the stack
esp points to the top of it
(which is now the bottom of your current stack frame)
yep
so you copy that to ebp so now ebp contains the bottom of your stack frame
and then you modify esp to grow your stack frame
(see the sub instruction)
so the boxes are called a stack frame i always wondered what a frame is
im a hopeless case
thanks a lotttt
then at the end you want to restore the stack frame when you return (because you don't want the stack frame messed up every time you call a function)
so you move the value in ebp back into esp moving all the values back to their original locations as if the call never happened
stack frame is just a conceptual thing. The space of the stack a single function is currently using
but assembly stack management is entirely based on stack frames in modern programming
btw this what the leave instruction does
there is also an enter instruction
so many words..
which does some of the stuff you see at the top, but in 1 instruction
thank you ill read all that tomorrow morning i cant take this anymore
https://en.wikipedia.org/wiki/X86_calling_conventions#cdecl see this for more information
wikipedia has a nice annotated assembly example
helps explain what each instruction is doing
@glossy crow Has your question been resolved? If so, type !solved :)