Re: push r1, pop r0

Matthijs Kooijman <[email protected]> Tue, 7 Nov 2017 21:48:55 +0100
Newsgroups gmane.comp.hardware.avr.gcc
Message-ID <[email protected]>
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
[email protected]
https://lists.nongnu.org/mailman/listinfo/avr-gcc-list
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEEvy580OCzZ3UVDV751ZOat/ByPIMFAloCHDIACgkQ1ZOat/By
PIMMTA/9GrS6kh9R5OnUT5xuO3J8Bz9Kfwl5hAUocPo5VEZeldbqrKejQvLj64+T
0g7WVDpjr3nmhkmI1nn/G/JWbnnGGOWZErKOCR+ghL/OC1BLzizXABwo8z92W/Gd
ZgCTPZs7MGzWtYqY+WxUD80JrFuX+H9iS+kBUCo5nb4svVjgSBHQAhaHN7IEM+Z0
HModcSQsT4tSVsYmf++3K1052zvq1XvQvWp2fjQGblIqoM1oXHWIfSJGX1dB2ZJh
fNb/UTnnvMbleO6v/wqvcNWIrrCRgFu/+StDovO5TNVqcsuk4p0kFo8FfDkOCBo+
ieGJvALEUEHHHIo8XpieXXv/flJYjse8OxAQ0jP7o7hEzOl1RXIKrqaTgI10HwXO
dz3fwBmK1DKqodKHBdcdu8KyRu9o8zuyOotNPgYtC93bT911STEulsi4LxNnbCKU
oCUGPIDZ0PAwn5GH9tsiZBDiOlLIwyRp8CYgE/KfQvF9ZZ7Oq1WZkV945MAkJzdr
7udDd/tylKUy9UkQabBcwn0cVXq+VRzs9G+RIlzpLZF3/adENEed2ZTEV0B5NWbd
vrte6W+2Q1Y0YafHMetBhp0PT2dvGLGeA8rNVGJ18a8vtJH9NtYjjE5LB4tQqYAj
GLxem9gJQeGNhzNoDWfBZ5+aZbtPFDwes9fWWzKyX7A5MmdaKSM=
=PLrF
-----END PGP SIGNATURE-----