[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] 24 bits (u)ints
From: |
Georg-Johann Lay |
Subject: |
Re: [avr-gcc-list] 24 bits (u)ints |
Date: |
Wed, 30 Nov 2016 14:14:23 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 |
On 30.11.2016 08:40, Diogo Martins Silva wrote:
Hello all.
The avr-gcc wiki (https://gcc.gnu.org/wiki/avr-gcc) lists 24 bits
(u)ints as an extension since version 4.7. How do I use them?
Thanks
Diogo
You can use it basically like any other integer type, for example:
__uint24 mul24 (unsigned char a, unsigned int b)
{
return (__uint24) a * b;
}
__int24 get_val24 (const __flash __int24 vals[], unsigned char pos)
{
return vals[pos];
}
For a MCU with MUL, this gives
mul24:
mul r24,r22
movw r18,r0
mul r24,r23
add r19,r0
mov r20,r1
clr __zero_reg__
adc r20,__zero_reg__
mov r24,r20
movw r22,r18
ret
get_val24:
ldi r18,lo8(3)
mul r22,r18
add r24,r0
adc r25,r1
clr __zero_reg__
movw r30,r24
lpm r22,Z+
lpm r23,Z+
lpm r24,Z
ret
When you are passing a 24-bit value to a variadic function like printf,
you have to cast it to (un)signed long by hand; avr-gcc does not
automatically promote such types to 32-bit types. printf et al. have no
format specifiers for 24-bit types.
Johann