Author Topic: x86_64 stack frame and alignment  (Read 25717 times)

Offline Rob Neff

  • Forum Moderator
  • Full Member
  • *****
  • Posts: 430
  • Country: us
Re: x86_64 stack frame and alignment
« Reply #15 on: August 04, 2013, 01:06:42 AM »
sure, but if we're talking about the Unix ABI, we can pass 6 integer arguments in the registers RDI, RSI, RDX, RCX, R8, R9 in that order. Furthermore, the registers XMM0-XMM7 are used to pass the single and double precision floating point arguments. It seems to me that a procedure or function which needs more than 14 parameters, is a little bit overloaded. But if we would need that, we could place the parameters inside an array and pass the array pointer to our procedure.

But no offense, in general you're right.

Gerhard

You're understanding is close but still not there yet.  The statement I made was regarding the calling convention's defined registers allocated for INTEGER or FLOATING_POINT.  The key word in that sentence is "or".  You are only thinking of 14 max registers, not of 6 INTEGER or 8 FLOATING_POINT registers.  Allow me to challenge you to write a simple program which calls the following X library window function:

Code: [Select]
Window XCreateSimpleWindow(Display *display, Window parent, int x, int y, unsigned int width, unsigned int height, unsigned int border_width, unsigned long border, unsigned long background);

This is not a function you've written.  It comes from a library that you must interface with thus you do not have the luxury of defining the interface nor of packaging up all the values into an array or struct and passing a simple pointer.  This particular function requires the use of 9 integer/pointer values and zero floating point values.

If you get stuck I'll let you peek into the NASMX Linux X64 Demo5 and examine the Nasm generated binary object file using objdump to see one way that this can be handled.  Hopefully this little challenge will strengthen your understanding of some of the subtleties of X64 programming.  ;)

Edit: spelling
« Last Edit: August 04, 2013, 01:20:39 AM by Rob Neff »

 

SMF spam blocked by CleanTalk