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, Szikra Istvan On Tue, Nov 7, 2017 at 9:48 PM, Matthijs Kooijman <matth...@stdin.nl> wrote: > Hi Szikra, > > I believe these pushes and pops are just meant to allocate 2 bytes on > the stack. > > > 222: cd b7 in r28, 0x3d ; 61 > > 224: de b7 in r29, 0x3e ; 62 > This loads Y with SP, so the location of the 2 pushed bytes > > > 226: 2e b7 in r18, 0x3e ; 62 > > 228: 8d b7 in r24, 0x3d ; 61 > > 22a: 90 e0 ldi r25, 0x00 ; 0 > > 22c: 92 2b or r25, r18 > This is the load SP from your code variable > > > 22e: 89 83 std Y+1, r24 ; 0x01 > > 230: 9a 83 std Y+2, r25 ; 0x02 > This stores SP to your sp variable on the stack > > > 232: 89 81 ldd r24, Y+1 ; 0x01 > > 234: 9a 81 ldd r25, Y+2 ; 0x02 > This loads your sp variable into the return value > > I wonder why this even forces the value onto the stack, since that's > really not needed at all. Perhaps the "volatile" on your "sp" variable > causes this, or perhaps you're compiling without optimization? > > Gr. > > Matthijs >
_______________________________________________ AVR-GCC-list mailing list AVR-GCC-list@nongnu.org https://lists.nongnu.org/mailman/listinfo/avr-gcc-list