But can you specify what happens inside the asm when I call a kernel function.
A kernel function from what kernel? Which O/S? You can't directly call functions used inside the kernel of an O/S unless your code resides within the kernel itself or within a module of the kernel.
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.
Because you said that kernel funcs dont pop anything from the stack so how it works??
I never said anything of the sort in relation to Operating systems.
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.
and what did you ment when you said the stack and sp should stay the same doesnt the stack should have the return addres??
Most C functions from the stdlib return their return value in eax but yes you can return it in the stack if you wanted to but that doesn't have anything to do with esp being the same as it was when the callee returns as it was when the callee was called.
I recommend you go buy Jeff duntemanns book asm programming the second edition and read if you're that interested in assembly.