Forum: ARM programming with GCC/GNU tools Variable length params and stack pointer alignment

Author: Justinas Saldukas (juxas)
Posted on:

Rate this post
0 useful
not useful

I am using olimex lpc-p2138(LPC2138) dev board with yagarto tools.
I have a function with variable length params(like sprintf) and have 
just found out how to get rid of 'random parameters'(upper dword is 
random) getting into my function, when passing 64bit integers as 
parameters(no problems with fixed length params or 32bit integers). If 
stack pointer is aligned to 8 bytes everything works as expected, but 
doesn't work with for example 4 byte alignment. Why is that? Is it the 
same as with 32bit integer loading from unaligned addresses? If it is, 
could you please tell which instruction causes this, so I can see the 
reason in documentation.

My test code:
volatile int64_t  gSum = 0;
void  out(int64_t a, ...)
  va_list l;
  va_start(l, a);
  a += va_arg(l, int64_t); // i think here it takes

  gSum = a;

int  main (void)


    out((int64_t)5, (int64_t)12);

    char  buf[32] = {0};
    buf[itoa_ll(gSum, buf, 32)] = '\n';


  return 0;



Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]

Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.