I have been a C/C++ programmer for 4 years now, and now that I'm actually reading a tut on it, I have to say, I am impressed! The whole concept of the DS really is cool; and it's flexability is the best I have seen.

While I was reading one of the lessons I noticed how they mentioned that the ESP changed according the data pushed.
So, would the following code be considered valid?

mov ebx, esp
push dword [first_var]
push dword [middle_var]
push dword [last_var]
call [my_function]
mov esp, ebx

Recommended Answers

All 3 Replies

Assuming EBX isn't clobbered by the function, then yes, it should work.

In my opinion its bad practice to do that. Though as already said its valid if EBX remains unchanged after the function returns.

Yes, it is bad practice. But the caller's question was, as I understood it, more to the way the stack actually works than to the propriety of doing it.

I could be wrong.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.