But on the other hand the code generated by avr-gcc (4.9.2) on my
machine does
not extend 8-bit results to 16 bits.
example:
~~~
int8_t signed8(void)
{
return -1;
}
~~~
generated:
~~~
00000034 <signed8>:
34: 8f ef ldi r24, 0xFF ; 255
36: 08 95 ret
~~~
I would have expected:
~~~
00000034 <signed8>:
34: 8f ef ldi r24, 0xFF ; 255
36: 9f ef ldi r25, 0xFF ; 255
38: 08 95 ret
~~~
Also a function using the returned result (cast to int16_t) does not
rely on
the called function to already have sign-extended its result; it rather
performs the sign extension itself:
~~~
#include <stdint.h>
int8_t signed8(void);
void write16(int16_t val);
int main(void)
{
write16(signed8());
return 0;
}
~~~
generated:
~~~
0000003c <main>:
3c: fb df rcall .-10 ; 0x34 <signed8>
3e: 08 2e mov r0, r24
40: 00 0c add r0, r0
42: 99 0b sbc r25, r25
44: f9 df rcall .-14 ; 0x38 <write16>
46: 80 e0 ldi r24, 0x00 ; 0
48: 90 e0 ldi r25, 0x00 ; 0
4a: 08 95 ret
~~~
I am using avr-gcc 4.9.2 (shipped with Debian 9.4).
Has the ABI changed since
the last update of the AVR-Libc FAQ (Tue Aug 12 2014),
and called functions no
longer need to extend 8-bit results to 16 bits?
best regards
Benoit.
p.s: I have recently started a topic on avrfreaks about this issue [2].
[1] https://www.nongnu.org/avr-libc/user-manual/FAQ.html#faq_reg_usage
[2] https://www.avrfreaks.net/forum/avr-gcc-abi-return-8-bit-value-function