Re: [avr-gcc-list] push r1, pop r0

2017-11-09 Thread David Brown
On 09/11/17 17:49, Szikra Istvan wrote: > Hi David, > > What is exactly wrong with my code? > > Thanks by the way for __get_PSP and all your help. This is getting into ARM stuff, and is therefore off-topic for the avr-gcc list (as you noted below). But the principles are fairly cross-target.

Re: [avr-gcc-list] push r1, pop r0

2017-11-09 Thread Georg-Johann Lay
On 09.11.2017 17:49, Szikra Istvan wrote: Hi David, What is exactly wrong with my code? Thanks by the way for __get_PSP and all your help. This is what it looks like on my end: __STATIC_INLINE uint32_t __get_PSP(void) { register uint32_t __regProcessStackPointer __ASM("psp"); Assuming th

Re: [avr-gcc-list] push r1, pop r0

2017-11-09 Thread Szikra Istvan
Hi David, What is exactly wrong with my code? Thanks by the way for __get_PSP and all your help. This is what it looks like on my end: __STATIC_INLINE uint32_t __get_PSP(void) { register uint32_t __regProcessStackPointer __ASM("psp"); return(__regProcessStackPointer); } in C:\Program Files

Re: [avr-gcc-list] push r1, pop r0

2017-11-09 Thread David Brown
On 09/11/17 04:57, Szikra Istvan wrote: > Hi > > Thanks for the SP, I missed that. > And apparently Atmel Studio also cannot find it, and underlines it with > red error marker. > It does compile, and I have found it in avr/common.h, it's probably a > problem with __AVR_ARCH__ handling by AS... >

Re: [avr-gcc-list] push r1, pop r0

2017-11-08 Thread Szikra Istvan
Hi Thanks for the SP, I missed that. And apparently Atmel Studio also cannot find it, and underlines it with red error marker. It does compile, and I have found it in avr/common.h, it's probably a problem with __AVR_ARCH__ handling by AS... I guess that's what I get for trusting the IDE:) I know

Re: [avr-gcc-list] push r1, pop r0

2017-11-08 Thread Georg-Johann Lay
Szikra Istvan schrieb: Hi all, I have this interesting test case for you guys, and girls. #include unsigned int GetStackPointer() { volatile unsigned int sp = (SPH << 8) | SPL; There is "SP" for you. Ne need to hamper with bytes. uint16_t GetStackPointer (void) { return SP; }

Re: [avr-gcc-list] push r1, pop r0

2017-11-08 Thread Matthijs Kooijman
Hi Szikra, > So it is 2017, but the compiler still cannot optimize away bitwise or > zero... :( I think this is https://gcc.gnu.org/bugzilla/show_bug.cgi?id=41076 (which should be fixed in gcc 7 according to the comments). The fix contains a peephole optimization that I think catches exactly this

Re: [avr-gcc-list] push r1, pop r0

2017-11-08 Thread Szikra Istvan
Hi all, I'm writing C++ code, but I made the example a C project. Yeah (void) I do use stdint.h, stddef.h, stdbool.h I just try to avoid the include hell for examples. ;) Note: avr/io.h already includes inttypes.h which includes stdint.h, so I probably should have used uint16_t. I use GetStackPo

Re: [avr-gcc-list] push r1, pop r0

2017-11-08 Thread David Brown
On 08/11/17 10:21, Sergey A. Borshch wrote: > On 08.11.2017 11:03, David Brown wrote: >> (Also, if you are writing C rather >> than C++, your function declaration is not correct.) The sensible way >> to write this is: >> >> static inline uint16_t GetStackPointer(void) >> { >> return (SPH << 8)

Re: [avr-gcc-list] push r1, pop r0

2017-11-08 Thread Sergey A. Borshch
On 08.11.2017 11:03, David Brown wrote: (Also, if you are writing C rather than C++, your function declaration is not correct.) The sensible way to write this is: static inline uint16_t GetStackPointer(void) { return (SPH << 8) | SPL; } It's not correct declaration too. Function name cl

Re: [avr-gcc-list] push r1, pop r0

2017-11-08 Thread David Brown
On 07/11/17 20:36, Szikra Istvan wrote: > Hi all, > > I have this interesting test case for you guys, and girls. > > > #include > > unsigned int GetStackPointer() > { > volatile unsigned int sp = (SPH << 8) | SPL; > return sp; > } > > int main(void) > { > while(1) > { >

Re: [avr-gcc-list] push r1, pop r0

2017-11-07 Thread Szikra Istvan
Hi Matthijs, I believe you are right, that makes sense. (I should have realized that, but it was a quite a while ago I read/wrote AVR asm... well you learn something new every day;) Thank you. It was compiled with -O1. Compiling with -Os does not seem to make a difference. Best regards, Szikr

Re: [avr-gcc-list] push r1, pop r0

2017-11-07 Thread Matthijs Kooijman
Hi Szikra, I believe these pushes and pops are just meant to allocate 2 bytes on the stack. > 222: cd b7in r28, 0x3d ; 61 > 224: de b7in r29, 0x3e ; 62 This loads Y with SP, so the location of the 2 pushed bytes > 226: 2e b7in r18, 0x3e ; 62 > 228: 8d b7in r24

[avr-gcc-list] push r1, pop r0

2017-11-07 Thread Szikra Istvan
Hi all, I have this interesting test case for you guys, and girls. #include unsigned int GetStackPointer() { volatile unsigned int sp = (SPH << 8) | SPL; return sp; } int main(void) { while(1) { PORTA.OUT = GetStackPointer(); } } After building it with Atmel Studi