home bbs files messages ]

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,746 of 4,675   
   Alex McDonald to Terje Mathisen   
   Re: Manners everyone!   
   03 Jan 19 15:18:27   
   
   From: alex@nospicedham.rivadpm.com   
      
   On 03-Jan-19 10:31, Terje Mathisen wrote:   
      
   >   
   > Personally I rather like passing a few parameters in registers,   
   > particularly to leaf functions, but for recursion using the stack is   
   > pretty much always at least as good.   
      
   One thing I haven't seen discussed here is using two stacks. (It might   
   have been, and I've missed it, so apologies in that case. And yes, this   
   is very Forth-ish.)   
      
   The first stack is for CALL/RET and PUSH/POP (or MOV) pairs for temp   
   storage, and is based on xSP; the second stack is the classic   
   parameter/locals frame, and can be based off just about any register   
   (xBP for instance).   
      
   C-type languages use this technique, except the single physical stack   
   has the two stacks (call/ret on xSP and frame on xBP) interwoven.   
   Separating them out can make for some interesting efficiencies, like   
   tail-call elimination, and some significant simplifications.   
      
   >   
   > As long as you are using a post-1986 CPU you can use stack-relative   
   > adressing, in which case EBP is perfectly usable as a regular register,   
   > you just need to do the housekeeping/math needed to figure out exactly   
   > where everything is located at all times, while the stack grows ans   
   > shrinks.   
      
   Even that can be avoided by using MOV to a fixed negative offset from   
   xSP instead of PUSH/POP. Then xSP doesn't need to change at all inside   
   the function.   
      
   64 bit Linux has the concept of a "red zone"; the space from [rsp-128]   
   to [rsp-8]. Windows has a different implementation with a 32 byte   
   "shadow space" immediately after the return address. Both reduce changes   
   of RSP during calls.   
      
   I can't find the reference (Xmas depleted my google-fu) but there was   
   some discussion about these mechanisms benefiting performance by   
   reducing the PUSH/POP activity (inefficient on later Intel chipsets?)   
   and replacing them with MOVs. I may be misremembering though.   
      
   --   
   Alex   
      
   --- 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