![]() |
| ||
| New to Win32 ASM programming I started with masm32 and i have some questions I read this Quote:
Can anybody explain how this works?? Coz I dont see any need in balancing stack first we push 3 params then calling the func now i guess sp goes 2 bytes up and than the functions pops the three params to use em.. Then sp goes 8 bytes down to the return address and returns no>???? this is how i imagine api funcs work mov ax,2 so why balance stack if its all goes nice?? anybody please explain how win32 func call work.. |
| ||
| Re: New to Win32 ASM programming There's one very large difference between pascal and C. C contains functions with the ability to accept variable amounts of arguments. Such as... printf. Pascal doesn't have(?)/can't handle variables argument implementations very well. And your call to lets say printf would look like.. push eax ;lets say contains the number 15 So that printf call would look like this in C int i = 15; There's more to the C calling convention as well such as the preservation of certain registers. |
| ||
| Re: New to Win32 ASM programming ok but why the caller balance the stack?? doesnt the function balances it after it returns?? just call _printf why does the caller balances the stack and not the function itself?? |
| ||
| Re: New to Win32 ASM programming ok but why the caller should balance the stack after the function execution doesnt the function balances the stack when it pops the arguments?? |
| ||
| Re: New to Win32 ASM programming Quote:
The C calling convention is the way it is because that's how it was designed for not only the language but also for unix. It's easier to implement variable argument length functions such as printf if the caller handles cleaning up the stack. It's also more stable because in the C calling convention a large majority of the registers are considered 'sacred' including ebp and esp so if I call a function then I can expect ebp and esp to be in the same condition as they were before I called that function. So you don't want to do it then huh? You want the calling function to do it? That's fine then write your own functions/macros in assembly and don't worry about it. You want to utilize that wealth of usefulness known as the C standard library? Alright then you gotta play by it's rules. (Also note you're playing by the OSs rules as well) Like writing drivers for linux, yeah some parts of the kernels system calls I don't like for writing drivers but what's my other option? Writing my own kernel.... |
| ||
| Re: New to Win32 ASM programming Thank you man you explained me a lot of new things I never knew before. But can you specify what happens inside the asm when I call a kernel function. Because you said that kernel funcs dont pop anything from the stack so how it works?? can you tell me what happens in theory inside the func and give me some asm code to realize it better?? and what did you ment when you said the stack and sp should stay the same doesnt the stack should have the return addres?? Please answer my questions Its very important for me btw I very appreciate your help!! |
| |||
| Re: New to Win32 ASM programming Quote:
Most o/s's however have a system call interface to help drivers and user programs accomplish what they need to do such as I/O. Whatever goes on inside that system call when it's called is completely dependent on it's code. Quote:
If you're referring to me saying that in the C calling convention the C function called doesn't pop anything off the stack then what I was saying is.. the function doesn't pop something off the stack with the intention of fixing the stack for the caller. If the function wants to pop something off the stack then it just sets up the stack pointers so that it can then the stack pointers are changed back to how they were before the function was called before the function returns to the caller. Although in more times then not it's easier to just referencing stuff on the stack like an array of memory like [ebp - 4] or the likes. I'm not going to write you asm code because quite frankly I don't think you understand a lick of assembly. Quote:
I recommend you go buy Jeff duntemanns book asm programming the second edition and read if you're that interested in assembly. |
| ||
| Re: New to Win32 ASM programming Thanks man anyway i found the explanation here http://www.delphi3000.com/articles/article_3771.asp?SK= and why did you say that i dont understand lick of asm the fact that you are a pro coder with expirience and you learned all this stuff for years and I am a 15 years old guy that just started learning asm at school doesnt means you have to be rude .... plus i know all the asm basics: 8086 instructions stack interputs procedures macros memory calculating. in my school we just started learning 8086 and i learned it in 2 months from reading in internet and asking questions from nice people like you. i dont know shit about win32 asm thats why I ask questions from you... by the way I read all the asm codes here and understood em very well if you could just show me some little piece of code like that i wouldnt have to google it http://www.delphi3000.com/articles/article_3771.asp?SK= i understood that it works by moving to bp the stack pointer and than use bp to move values from stack i mean bp role plays sp for the time win32 function is called and than bp pops back to restore its original value than it returns and adds to sp few bytes.. that explain whys you said stack and bp stay the same after func.. see i know some asm :) anyway thank you very much for your help you really know alot about programming!!!! srsly u rock dude just plesae no need to be rude :) i'm just kid lol |
| All times are GMT -4. The time now is 4:13 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC