Variable length params and stack pointer alignment

OP #2297522
Hello,

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:
1
volatile int64_t  gSum = 0;
2
void  out(int64_t a, ...)
3
{
4
  va_list l;
5
  va_start(l, a);
6
  a += va_arg(l, int64_t); // i think here it takes
7
  va_end(l);
8

9
  gSum = a;
10
}
11

12
int  main (void)
13
{
14
  InitPLL();
15
  uart0_init(UART_BAUD(115200));
16

17
  for(;;)
18
  {
19
    while(!uart0_can_read());
20
    uart0_clean();
21

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

24
    char  buf[32] = {0};
25
    buf[itoa_ll(gSum, buf, 32)] = '\n';
26
    uart0_write_s(buf);
27

28
  }
29

30
  return 0;
31
}

Thanks.
Justinas

Reply

A question of your own? This thread is over 15 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.