Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.asm.x86    |    Ahh, the lost art of x86 assembly    |    4,675 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 3,723 of 4,675    |
|    James Harris to All    |
|    Locals, parameters, callee-save register    |
|    31 Dec 18 17:20:53    |
      From: james.harris.1@nospicedham.gmail.com              This is a query about how best to lay out an x86 activation record which       has to contain locals and callee-save registers.              Traditionally, a function might begin with               push ebp        mov ebp, esp              and end with               pop ebp        ret              That, conveniently, allows stack-based parameters to be accessed as       offsets from EBP with [EBP + n]. However, it doesn't allow any space in       which to put function locals (variables which are local to each       activation of the function).              If space were needed for locals the prologue might become               push ebp        mov ebp, esp        sub esp, N ;N is the number of bytes to be set aside for locals              The corresponding exit from the function would be               mov esp, ebp ;Allow for locals (and other ESP alterations)        pop ebp        ret              That still allows parameters to be accessed as [EBP + n] but it now also       allows locals to be accessed as [EBP - n].              My query, though, is over where and how it is best to add the       preservation of callee-save registers to that lot. To make an example,       say that ESI and EDI are to be saved. I would, until now, have started a       function with               push ebp        mov ebp, esp        push edi        push esi              and ended it with               pop esi        pop edi        pop ebp        ret              But is that the best way?              If you were not constrained by an existing convention (or even if you       have a favourite convention) would you make space for locals before or       after saving registers? Or would you, in fact, save registers before       pushing EBP?              I am thinking to do the latter. Will explain the reasons for that in a       reply. But I guess it's unconventional and non-standard so I wondered       what others thought or had found was the best thing to do.              So the basic query is: if given free rein on x86 how would you recommend       storing callee-save registers and locals while providing convenient       access to stack-based parameters?                     --       James Harris              --- SoupGate-Win32 v1.05        * Origin: you cannot sedate... all the things you hate (1:229/2)    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca