|
Prev: Why bother subtracting for local variables? (x86 c calling convention)
Next: Inquiries about Jesus Christ
From: Frank Kotler on 4 Jul 2008 18:50 JK.Lists.questions(a)gmail.com wrote: > I've looked through several references, but I can't find anything that > explains why we bother subtracting from esp when storing local > variables. One reference indicates that it prevents locals from > getting clobbered. How would they be clobbered if local variables > were stored on the stack via the usual push and pop? > > This must be something obvious. ty in advance. --jk Push *does* subtract from esp. The "risk" would be from putting local variables below esp *without* subtracting anything from esp. Then, if you pushed anything, it would clobber your locals. Even if *you* don't push anything, an interrupt may use the stack (clobbering your locals). In modern OSen, interrupts use their own - separate - stack, so you *can* put locals below esp... provided you don't clobber 'em yourself. I don't think I'd recommend this, but it works... Push and pop should be fine, in any case... subject to the disadvantages Robert mentions. (push/pop are, in recent CPUs, slow compared to mov.. shorter, though) Best, Frank |