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